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. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 19 | * Author: Dave Houlton <daveh@lunarg.com> |
| 20 | * Shannon McPherson <shannon@lunarg.com> |
| 21 | */ |
| 22 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 23 | #include <cmath> |
| 24 | #include <set> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 25 | |
| 26 | #include "vk_enum_string_helper.h" |
| 27 | #include "vk_format_utils.h" |
| 28 | #include "vk_layer_data.h" |
| 29 | #include "vk_layer_utils.h" |
| 30 | #include "vk_layer_logging.h" |
| 31 | #include "vk_typemap_helper.h" |
| 32 | |
| 33 | #include "chassis.h" |
| 34 | #include "state_tracker.h" |
| 35 | #include "shader_validation.h" |
| 36 | |
John Zulauf | 890b50b | 2020-06-17 15:18:19 -0600 | [diff] [blame] | 37 | const char *CommandTypeString(CMD_TYPE type) { |
| 38 | // Autogenerated as part of the vk_validation_error_message.h codegen |
| 39 | static const std::array<const char *, CMD_RANGE_SIZE> command_name_list = {{VUID_CMD_NAME_LIST}}; |
| 40 | return command_name_list[type]; |
| 41 | } |
| 42 | |
Mark Lobodzinski | b4ab6ac | 2020-04-02 13:12:06 -0600 | [diff] [blame] | 43 | void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) { |
| 44 | if (add_obj) { |
| 45 | instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type)); |
| 46 | // Call base class |
| 47 | ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj); |
| 48 | } |
| 49 | } |
| 50 | |
John Zulauf | 5c5e88d | 2019-12-26 11:22:02 -0700 | [diff] [blame] | 51 | uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { |
| 52 | // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS |
| 53 | uint32_t mip_level_count = range->levelCount; |
| 54 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
| 55 | mip_level_count = mip_levels - range->baseMipLevel; |
| 56 | } |
| 57 | return mip_level_count; |
| 58 | } |
| 59 | |
| 60 | uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { |
| 61 | // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS |
| 62 | uint32_t array_layer_count = range->layerCount; |
| 63 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 64 | array_layer_count = layers - range->baseArrayLayer; |
| 65 | } |
| 66 | return array_layer_count; |
| 67 | } |
| 68 | |
| 69 | VkImageSubresourceRange NormalizeSubresourceRange(const VkImageCreateInfo &image_create_info, |
| 70 | const VkImageSubresourceRange &range) { |
| 71 | VkImageSubresourceRange norm = range; |
| 72 | norm.levelCount = ResolveRemainingLevels(&range, image_create_info.mipLevels); |
| 73 | |
| 74 | // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR flag bit, where <extent.depth> and |
| 75 | // <arrayLayers> can potentially alias. |
| 76 | uint32_t layer_limit = (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) |
| 77 | ? image_create_info.extent.depth |
| 78 | : image_create_info.arrayLayers; |
| 79 | norm.layerCount = ResolveRemainingLayers(&range, layer_limit); |
| 80 | |
| 81 | // For multiplanar formats, IMAGE_ASPECT_COLOR is equivalent to adding the aspect of the individual planes |
| 82 | VkImageAspectFlags &aspect_mask = norm.aspectMask; |
| 83 | if (FormatIsMultiplane(image_create_info.format)) { |
| 84 | if (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 85 | aspect_mask &= ~VK_IMAGE_ASPECT_COLOR_BIT; |
| 86 | aspect_mask |= (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT); |
| 87 | if (FormatPlaneCount(image_create_info.format) > 2) { |
| 88 | aspect_mask |= VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | return norm; |
| 93 | } |
| 94 | |
| 95 | VkImageSubresourceRange NormalizeSubresourceRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range) { |
| 96 | const VkImageCreateInfo &image_create_info = image_state.createInfo; |
| 97 | return NormalizeSubresourceRange(image_create_info, range); |
| 98 | } |
| 99 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 100 | // NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS" |
| 101 | // attachments won't persist past the API entry point exit. |
| 102 | std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin, |
| 103 | const FRAMEBUFFER_STATE &fb_state) { |
| 104 | const VkImageView *attachments = fb_state.createInfo.pAttachments; |
| 105 | uint32_t count = fb_state.createInfo.attachmentCount; |
| 106 | if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
| 107 | const auto *framebuffer_attachments = lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext); |
| 108 | if (framebuffer_attachments) { |
| 109 | attachments = framebuffer_attachments->pAttachments; |
| 110 | count = framebuffer_attachments->attachmentCount; |
| 111 | } |
| 112 | } |
| 113 | return std::make_pair(count, attachments); |
| 114 | } |
| 115 | |
| 116 | std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetAttachmentViews(const VkRenderPassBeginInfo &rp_begin, |
| 117 | const FRAMEBUFFER_STATE &fb_state) const { |
| 118 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 119 | |
| 120 | const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state); |
| 121 | const auto attachment_count = count_attachment.first; |
| 122 | const auto *attachments = count_attachment.second; |
| 123 | views.resize(attachment_count, nullptr); |
| 124 | for (uint32_t i = 0; i < attachment_count; i++) { |
| 125 | if (attachments[i] != VK_NULL_HANDLE) { |
| 126 | views[i] = Get<IMAGE_VIEW_STATE>(attachments[i]); |
| 127 | } |
| 128 | } |
| 129 | return views; |
| 130 | } |
| 131 | |
| 132 | std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetCurrentAttachmentViews(const CMD_BUFFER_STATE &cb_state) const { |
| 133 | // Only valid *after* RecordBeginRenderPass and *before* RecordEndRenderpass as it relies on cb_state for the renderpass info. |
| 134 | std::vector<const IMAGE_VIEW_STATE *> views; |
| 135 | |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 136 | const auto *rp_state = cb_state.activeRenderPass.get(); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 137 | if (!rp_state) return views; |
| 138 | const auto &rp_begin = *cb_state.activeRenderPassBeginInfo.ptr(); |
| 139 | const auto *fb_state = Get<FRAMEBUFFER_STATE>(rp_begin.framebuffer); |
| 140 | if (!fb_state) return views; |
| 141 | |
| 142 | return GetAttachmentViews(rp_begin, *fb_state); |
| 143 | } |
| 144 | |
locke-lunarg | 3e127c7 | 2020-06-09 17:45:28 -0600 | [diff] [blame] | 145 | PIPELINE_STATE *GetCurrentPipelineFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint) { |
| 146 | const auto last_bound_it = cmd.lastBound.find(pipelineBindPoint); |
| 147 | if (last_bound_it == cmd.lastBound.cend()) { |
| 148 | return nullptr; |
| 149 | } |
| 150 | return last_bound_it->second.pipeline_state; |
| 151 | } |
| 152 | |
| 153 | void GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint, |
| 154 | const PIPELINE_STATE **rtn_pipe, |
| 155 | const std::vector<LAST_BOUND_STATE::PER_SET> **rtn_sets) { |
| 156 | const auto last_bound_it = cmd.lastBound.find(pipelineBindPoint); |
| 157 | if (last_bound_it == cmd.lastBound.cend()) { |
| 158 | return; |
| 159 | } |
| 160 | *rtn_pipe = last_bound_it->second.pipeline_state; |
| 161 | *rtn_sets = &(last_bound_it->second.per_set); |
| 162 | } |
| 163 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 164 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 165 | // Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR |
| 166 | // This could also move into a seperate core_validation_android.cpp file... ? |
| 167 | |
| 168 | void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) { |
| 169 | const VkExternalMemoryImageCreateInfo *emici = lvl_find_in_chain<VkExternalMemoryImageCreateInfo>(create_info->pNext); |
| 170 | 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] | 171 | is_node->external_ahb = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 172 | } |
| 173 | const VkExternalFormatANDROID *ext_fmt_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext); |
| 174 | if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) { |
| 175 | is_node->has_ahb_format = true; |
| 176 | is_node->ahb_format = ext_fmt_android->externalFormat; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 177 | // VUID 01894 will catch if not found in map |
| 178 | auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat); |
| 179 | if (it != ahb_ext_formats_map.end()) { |
| 180 | is_node->format_features = it->second; |
| 181 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 185 | void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) { |
| 186 | const VkExternalMemoryBufferCreateInfo *embci = lvl_find_in_chain<VkExternalMemoryBufferCreateInfo>(create_info->pNext); |
| 187 | if (embci && (embci->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { |
| 188 | bs_node->external_ahb = true; |
| 189 | } |
| 190 | } |
| 191 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 192 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info, |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 193 | VkSamplerYcbcrConversion ycbcr_conversion, |
| 194 | SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 195 | const VkExternalFormatANDROID *ext_format_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext); |
| 196 | if (ext_format_android && (0 != ext_format_android->externalFormat)) { |
| 197 | ycbcr_conversion_ahb_fmt_map.emplace(ycbcr_conversion, ext_format_android->externalFormat); |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 198 | // VUID 01894 will catch if not found in map |
| 199 | auto it = ahb_ext_formats_map.find(ext_format_android->externalFormat); |
| 200 | if (it != ahb_ext_formats_map.end()) { |
| 201 | ycbcr_state->format_features = it->second; |
| 202 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 203 | } |
| 204 | }; |
| 205 | |
| 206 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion) { |
| 207 | ycbcr_conversion_ahb_fmt_map.erase(ycbcr_conversion); |
| 208 | }; |
| 209 | |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 210 | void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID( |
| 211 | VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) { |
| 212 | if (VK_SUCCESS != result) return; |
| 213 | auto ahb_format_props = lvl_find_in_chain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext); |
| 214 | if (ahb_format_props) { |
| 215 | ahb_ext_formats_map.insert({ahb_format_props->externalFormat, ahb_format_props->formatFeatures}); |
| 216 | } |
| 217 | } |
| 218 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 219 | #else |
| 220 | |
| 221 | void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {} |
| 222 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 223 | void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {} |
| 224 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 225 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info, |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 226 | VkSamplerYcbcrConversion ycbcr_conversion, |
| 227 | SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state){}; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 228 | |
| 229 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion){}; |
| 230 | |
| 231 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 232 | |
Mark Lobodzinski | d3ec86f | 2020-03-18 11:23:04 -0600 | [diff] [blame] | 233 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> GetDslFromPipelineLayout(PIPELINE_LAYOUT_STATE const *layout_data, |
| 234 | uint32_t set) { |
| 235 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> dsl = nullptr; |
| 236 | if (layout_data && (set < layout_data->set_layouts.size())) { |
| 237 | dsl = layout_data->set_layouts[set]; |
| 238 | } |
| 239 | return dsl; |
| 240 | } |
| 241 | |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 242 | void AddImageStateProps(IMAGE_STATE &image_state, const VkDevice device, const VkPhysicalDevice physical_device) { |
| 243 | // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features) |
| 244 | // if format is AHB external format then the features are already set |
| 245 | if (image_state.has_ahb_format == false) { |
| 246 | const VkImageTiling image_tiling = image_state.createInfo.tiling; |
| 247 | const VkFormat image_format = image_state.createInfo.format; |
| 248 | if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 249 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = { |
| 250 | VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, nullptr}; |
| 251 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state.image, &drm_format_properties); |
| 252 | |
| 253 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 254 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 255 | nullptr}; |
| 256 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 257 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2); |
Lionel Landwerlin | 09351a7 | 2020-06-22 18:15:59 +0300 | [diff] [blame] | 258 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 259 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 260 | drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0]; |
| 261 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 262 | |
| 263 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 264 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == |
| 265 | drm_format_properties.drmFormatModifier) { |
| 266 | image_state.format_features = |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 267 | drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 268 | break; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | } else { |
| 272 | VkFormatProperties format_properties; |
| 273 | DispatchGetPhysicalDeviceFormatProperties(physical_device, image_format, &format_properties); |
| 274 | image_state.format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 275 | : format_properties.optimalTilingFeatures; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 280 | void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 281 | const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) { |
| 282 | if (VK_SUCCESS != result) return; |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 283 | auto is_node = std::make_shared<IMAGE_STATE>(device, *pImage, pCreateInfo); |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 284 | is_node->disjoint = ((pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) != 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 285 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 286 | RecordCreateImageANDROID(pCreateInfo, is_node.get()); |
| 287 | } |
| 288 | const auto swapchain_info = lvl_find_in_chain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext); |
| 289 | if (swapchain_info) { |
| 290 | is_node->create_from_swapchain = swapchain_info->swapchain; |
| 291 | } |
| 292 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 293 | // Record the memory requirements in case they won't be queried |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 294 | // External AHB memory can't be queried until after memory is bound |
Spencer Fricke | 224c985 | 2020-04-06 07:47:29 -0700 | [diff] [blame] | 295 | if (is_node->external_ahb == false) { |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 296 | if (is_node->disjoint == false) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 297 | DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements); |
| 298 | } else { |
| 299 | uint32_t plane_count = FormatPlaneCount(pCreateInfo->format); |
| 300 | VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr}; |
| 301 | VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr}; |
| 302 | VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2}; |
| 303 | mem_req_info2.pNext = &image_plane_req; |
| 304 | mem_req_info2.image = *pImage; |
| 305 | |
| 306 | assert(plane_count != 0); // assumes each format has at least first plane |
| 307 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT; |
| 308 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 309 | is_node->plane0_requirements = mem_reqs2.memoryRequirements; |
| 310 | |
| 311 | if (plane_count >= 2) { |
| 312 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 313 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 314 | is_node->plane1_requirements = mem_reqs2.memoryRequirements; |
| 315 | } |
| 316 | if (plane_count >= 3) { |
| 317 | image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 318 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 319 | is_node->plane2_requirements = mem_reqs2.memoryRequirements; |
| 320 | } |
| 321 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 322 | } |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 323 | |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 324 | AddImageStateProps(*is_node, device, physical_device); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 325 | |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 326 | is_node->unprotected = ((pCreateInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0); |
| 327 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 328 | imageMap.insert(std::make_pair(*pImage, std::move(is_node))); |
| 329 | } |
| 330 | |
| 331 | void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
| 332 | if (!image) return; |
| 333 | IMAGE_STATE *image_state = GetImageState(image); |
| 334 | const VulkanTypedHandle obj_struct(image, kVulkanObjectTypeImage); |
| 335 | InvalidateCommandBuffers(image_state->cb_bindings, obj_struct); |
| 336 | // Clean up memory mapping, bindings and range references for image |
| 337 | for (auto mem_binding : image_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 338 | RemoveImageMemoryRange(image, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 339 | } |
| 340 | if (image_state->bind_swapchain) { |
| 341 | auto swapchain = GetSwapchainState(image_state->bind_swapchain); |
| 342 | if (swapchain) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 343 | 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] | 344 | } |
| 345 | } |
| 346 | RemoveAliasingImage(image_state); |
| 347 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 348 | image_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 349 | // Remove image from imageMap |
| 350 | imageMap.erase(image); |
| 351 | } |
| 352 | |
| 353 | void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, |
| 354 | VkImageLayout imageLayout, const VkClearColorValue *pColor, |
| 355 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 356 | auto cb_node = GetCBState(commandBuffer); |
| 357 | auto image_state = GetImageState(image); |
| 358 | if (cb_node && image_state) { |
| 359 | AddCommandBufferBindingImage(cb_node, image_state); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 364 | VkImageLayout imageLayout, |
| 365 | const VkClearDepthStencilValue *pDepthStencil, |
| 366 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 367 | auto cb_node = GetCBState(commandBuffer); |
| 368 | auto image_state = GetImageState(image); |
| 369 | if (cb_node && image_state) { |
| 370 | AddCommandBufferBindingImage(cb_node, image_state); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 375 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 376 | uint32_t regionCount, const VkImageCopy *pRegions) { |
| 377 | auto cb_node = GetCBState(commandBuffer); |
| 378 | auto src_image_state = GetImageState(srcImage); |
| 379 | auto dst_image_state = GetImageState(dstImage); |
| 380 | |
| 381 | // Update bindings between images and cmd buffer |
| 382 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 383 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 384 | } |
| 385 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame^] | 386 | void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 387 | const VkCopyImageInfo2KHR *pCopyImageInfo) { |
| 388 | auto cb_node = GetCBState(commandBuffer); |
| 389 | auto src_image_state = GetImageState(pCopyImageInfo->srcImage); |
| 390 | auto dst_image_state = GetImageState(pCopyImageInfo->dstImage); |
| 391 | |
| 392 | // Update bindings between images and cmd buffer |
| 393 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 394 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 395 | } |
| 396 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 397 | void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 398 | VkImageLayout srcImageLayout, VkImage dstImage, |
| 399 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 400 | const VkImageResolve *pRegions) { |
| 401 | auto cb_node = GetCBState(commandBuffer); |
| 402 | auto src_image_state = GetImageState(srcImage); |
| 403 | auto dst_image_state = GetImageState(dstImage); |
| 404 | |
| 405 | // Update bindings between images and cmd buffer |
| 406 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 407 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 408 | } |
| 409 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame^] | 410 | void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 411 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
| 412 | auto cb_node = GetCBState(commandBuffer); |
| 413 | auto src_image_state = GetImageState(pResolveImageInfo->srcImage); |
| 414 | auto dst_image_state = GetImageState(pResolveImageInfo->dstImage); |
| 415 | |
| 416 | // Update bindings between images and cmd buffer |
| 417 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 418 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 419 | } |
| 420 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 421 | void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 422 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 423 | uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 424 | auto cb_node = GetCBState(commandBuffer); |
| 425 | auto src_image_state = GetImageState(srcImage); |
| 426 | auto dst_image_state = GetImageState(dstImage); |
| 427 | |
| 428 | // Update bindings between images and cmd buffer |
| 429 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 430 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 431 | } |
| 432 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame^] | 433 | void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 434 | const VkBlitImageInfo2KHR *pBlitImageInfo) { |
| 435 | auto cb_node = GetCBState(commandBuffer); |
| 436 | auto src_image_state = GetImageState(pBlitImageInfo->srcImage); |
| 437 | auto dst_image_state = GetImageState(pBlitImageInfo->dstImage); |
| 438 | |
| 439 | // Update bindings between images and cmd buffer |
| 440 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 441 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 442 | } |
| 443 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 444 | void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, |
| 445 | const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer, |
| 446 | VkResult result) { |
| 447 | if (result != VK_SUCCESS) return; |
| 448 | // 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] | 449 | auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 450 | |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 451 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 452 | RecordCreateBufferANDROID(pCreateInfo, buffer_state.get()); |
| 453 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 454 | // Get a set of requirements in the case the app does not |
sfricke-samsung | ad90e72 | 2020-07-08 20:54:24 -0700 | [diff] [blame] | 455 | DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 456 | |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 457 | buffer_state->unprotected = ((pCreateInfo->flags & VK_BUFFER_CREATE_PROTECTED_BIT) == 0); |
| 458 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 459 | bufferMap.insert(std::make_pair(*pBuffer, std::move(buffer_state))); |
| 460 | } |
| 461 | |
| 462 | void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo, |
| 463 | const VkAllocationCallbacks *pAllocator, VkBufferView *pView, |
| 464 | VkResult result) { |
| 465 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 466 | auto buffer_state = GetBufferShared(pCreateInfo->buffer); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 467 | auto buffer_view_state = std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo); |
| 468 | |
| 469 | VkFormatProperties format_properties; |
| 470 | DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties); |
| 471 | buffer_view_state->format_features = format_properties.bufferFeatures; |
| 472 | |
| 473 | bufferViewMap.insert(std::make_pair(*pView, std::move(buffer_view_state))); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, |
| 477 | const VkAllocationCallbacks *pAllocator, VkImageView *pView, |
| 478 | VkResult result) { |
| 479 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 480 | auto image_state = GetImageShared(pCreateInfo->image); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 481 | auto image_view_state = std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo); |
| 482 | |
| 483 | // Add feature support according to Image View Format Features (vkspec.html#resources-image-view-format-features) |
| 484 | const VkImageTiling image_tiling = image_state->createInfo.tiling; |
| 485 | const VkFormat image_view_format = pCreateInfo->format; |
| 486 | if (image_state->has_ahb_format == true) { |
| 487 | // The ImageView uses same Image's format feature since they share same AHB |
| 488 | image_view_state->format_features = image_state->format_features; |
| 489 | } else if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 490 | // Parameter validation should catch if this is used without VK_EXT_image_drm_format_modifier |
| 491 | assert(device_extensions.vk_ext_image_drm_format_modifier); |
| 492 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, |
| 493 | nullptr}; |
| 494 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state->image, &drm_format_properties); |
| 495 | |
| 496 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 497 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 498 | nullptr}; |
| 499 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 500 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_view_format, &format_properties_2); |
| 501 | |
| 502 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 503 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) { |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 504 | image_view_state->format_features |= |
| 505 | drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
Lionel Landwerlin | 94f1ce3 | 2020-07-02 17:39:31 +0300 | [diff] [blame] | 506 | break; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | } else { |
| 510 | VkFormatProperties format_properties; |
| 511 | DispatchGetPhysicalDeviceFormatProperties(physical_device, image_view_format, &format_properties); |
| 512 | image_view_state->format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 513 | : format_properties.optimalTilingFeatures; |
| 514 | } |
| 515 | |
| 516 | imageViewMap.insert(std::make_pair(*pView, std::move(image_view_state))); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 520 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
| 521 | auto cb_node = GetCBState(commandBuffer); |
| 522 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 523 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 524 | |
| 525 | // Update bindings between buffers and cmd buffer |
| 526 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 527 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 528 | } |
| 529 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame^] | 530 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 531 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
| 532 | auto cb_node = GetCBState(commandBuffer); |
| 533 | auto src_buffer_state = GetBufferState(pCopyBufferInfos->srcBuffer); |
| 534 | auto dst_buffer_state = GetBufferState(pCopyBufferInfos->dstBuffer); |
| 535 | |
| 536 | // Update bindings between buffers and cmd buffer |
| 537 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 538 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 539 | } |
| 540 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 541 | void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView, |
| 542 | const VkAllocationCallbacks *pAllocator) { |
| 543 | IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView); |
| 544 | if (!image_view_state) return; |
| 545 | const VulkanTypedHandle obj_struct(imageView, kVulkanObjectTypeImageView); |
| 546 | |
| 547 | // Any bound cmd buffers are now invalid |
| 548 | InvalidateCommandBuffers(image_view_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 549 | image_view_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 550 | imageViewMap.erase(imageView); |
| 551 | } |
| 552 | |
| 553 | void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) { |
| 554 | if (!buffer) return; |
| 555 | auto buffer_state = GetBufferState(buffer); |
| 556 | const VulkanTypedHandle obj_struct(buffer, kVulkanObjectTypeBuffer); |
| 557 | |
| 558 | InvalidateCommandBuffers(buffer_state->cb_bindings, obj_struct); |
| 559 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 560 | RemoveBufferMemoryRange(buffer, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 561 | } |
| 562 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 563 | buffer_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 564 | bufferMap.erase(buffer_state->buffer); |
| 565 | } |
| 566 | |
| 567 | void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, |
| 568 | const VkAllocationCallbacks *pAllocator) { |
| 569 | if (!bufferView) return; |
| 570 | auto buffer_view_state = GetBufferViewState(bufferView); |
| 571 | const VulkanTypedHandle obj_struct(bufferView, kVulkanObjectTypeBufferView); |
| 572 | |
| 573 | // Any bound cmd buffers are now invalid |
| 574 | InvalidateCommandBuffers(buffer_view_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 575 | buffer_view_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 576 | bufferViewMap.erase(bufferView); |
| 577 | } |
| 578 | |
| 579 | void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 580 | VkDeviceSize size, uint32_t data) { |
| 581 | auto cb_node = GetCBState(commandBuffer); |
| 582 | auto buffer_state = GetBufferState(dstBuffer); |
| 583 | // Update bindings between buffer and cmd buffer |
| 584 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
| 585 | } |
| 586 | |
| 587 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 588 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, |
| 589 | uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
| 590 | auto cb_node = GetCBState(commandBuffer); |
| 591 | auto src_image_state = GetImageState(srcImage); |
| 592 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 593 | |
| 594 | // Update bindings between buffer/image and cmd buffer |
| 595 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 596 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 597 | } |
| 598 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame^] | 599 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 600 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
| 601 | auto cb_node = GetCBState(commandBuffer); |
| 602 | auto src_image_state = GetImageState(pCopyImageToBufferInfo->srcImage); |
| 603 | auto dst_buffer_state = GetBufferState(pCopyImageToBufferInfo->dstBuffer); |
| 604 | |
| 605 | // Update bindings between buffer/image and cmd buffer |
| 606 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 607 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
| 608 | } |
| 609 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 610 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 611 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 612 | const VkBufferImageCopy *pRegions) { |
| 613 | auto cb_node = GetCBState(commandBuffer); |
| 614 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 615 | auto dst_image_state = GetImageState(dstImage); |
| 616 | |
| 617 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 618 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 619 | } |
| 620 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame^] | 621 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 622 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
| 623 | auto cb_node = GetCBState(commandBuffer); |
| 624 | auto src_buffer_state = GetBufferState(pCopyBufferToImageInfo->srcBuffer); |
| 625 | auto dst_image_state = GetImageState(pCopyBufferToImageInfo->dstImage); |
| 626 | |
| 627 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 628 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
| 629 | } |
| 630 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 631 | // Get the image viewstate for a given framebuffer attachment |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 632 | IMAGE_VIEW_STATE *ValidationStateTracker::GetAttachmentImageViewState(CMD_BUFFER_STATE *cb, FRAMEBUFFER_STATE *framebuffer, |
| 633 | uint32_t index) { |
| 634 | if (framebuffer->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) { |
| 635 | assert(index < cb->imagelessFramebufferAttachments.size()); |
| 636 | return cb->imagelessFramebufferAttachments[index]; |
| 637 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 638 | assert(framebuffer && (index < framebuffer->createInfo.attachmentCount)); |
| 639 | const VkImageView &image_view = framebuffer->createInfo.pAttachments[index]; |
| 640 | return GetImageViewState(image_view); |
| 641 | } |
| 642 | |
| 643 | // Get the image viewstate for a given framebuffer attachment |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 644 | const IMAGE_VIEW_STATE *ValidationStateTracker::GetAttachmentImageViewState(const CMD_BUFFER_STATE *cb, |
| 645 | const FRAMEBUFFER_STATE *framebuffer, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 646 | uint32_t index) const { |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 647 | if (framebuffer->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) { |
| 648 | assert(index < cb->imagelessFramebufferAttachments.size()); |
| 649 | return cb->imagelessFramebufferAttachments[index]; |
| 650 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 651 | assert(framebuffer && (index < framebuffer->createInfo.attachmentCount)); |
| 652 | const VkImageView &image_view = framebuffer->createInfo.pAttachments[index]; |
| 653 | return GetImageViewState(image_view); |
| 654 | } |
| 655 | |
| 656 | void ValidationStateTracker::AddAliasingImage(IMAGE_STATE *image_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 657 | std::unordered_set<VkImage> *bound_images = nullptr; |
| 658 | |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 659 | if (image_state->bind_swapchain) { |
| 660 | auto swapchain_state = GetSwapchainState(image_state->bind_swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 661 | if (swapchain_state) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 662 | bound_images = &swapchain_state->images[image_state->bind_swapchain_imageIndex].bound_images; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 663 | } |
| 664 | } else { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 665 | if (image_state->binding.mem_state) { |
| 666 | bound_images = &image_state->binding.mem_state->bound_images; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
| 670 | if (bound_images) { |
| 671 | for (const auto &handle : *bound_images) { |
| 672 | if (handle != image_state->image) { |
| 673 | auto is = GetImageState(handle); |
| 674 | if (is && is->IsCompatibleAliasing(image_state)) { |
| 675 | auto inserted = is->aliasing_images.emplace(image_state->image); |
| 676 | if (inserted.second) { |
| 677 | image_state->aliasing_images.emplace(handle); |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | void ValidationStateTracker::RemoveAliasingImage(IMAGE_STATE *image_state) { |
| 686 | for (const auto &image : image_state->aliasing_images) { |
| 687 | auto is = GetImageState(image); |
| 688 | if (is) { |
| 689 | is->aliasing_images.erase(image_state->image); |
| 690 | } |
| 691 | } |
| 692 | image_state->aliasing_images.clear(); |
| 693 | } |
| 694 | |
| 695 | void ValidationStateTracker::RemoveAliasingImages(const std::unordered_set<VkImage> &bound_images) { |
| 696 | // This is one way clear. Because the bound_images include cross references, the one way clear loop could clear the whole |
| 697 | // reference. It doesn't need two ways clear. |
| 698 | for (const auto &handle : bound_images) { |
| 699 | auto is = GetImageState(handle); |
| 700 | if (is) { |
| 701 | is->aliasing_images.clear(); |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 706 | const EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) const { |
| 707 | auto it = eventMap.find(event); |
| 708 | if (it == eventMap.end()) { |
| 709 | return nullptr; |
| 710 | } |
| 711 | return &it->second; |
| 712 | } |
| 713 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 714 | EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) { |
| 715 | auto it = eventMap.find(event); |
| 716 | if (it == eventMap.end()) { |
| 717 | return nullptr; |
| 718 | } |
| 719 | return &it->second; |
| 720 | } |
| 721 | |
| 722 | const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const { |
| 723 | auto it = queueMap.find(queue); |
| 724 | if (it == queueMap.cend()) { |
| 725 | return nullptr; |
| 726 | } |
| 727 | return &it->second; |
| 728 | } |
| 729 | |
| 730 | QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) { |
| 731 | auto it = queueMap.find(queue); |
| 732 | if (it == queueMap.end()) { |
| 733 | return nullptr; |
| 734 | } |
| 735 | return &it->second; |
| 736 | } |
| 737 | |
| 738 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) const { |
| 739 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 740 | auto it = phys_dev_map->find(phys); |
| 741 | if (it == phys_dev_map->end()) { |
| 742 | return nullptr; |
| 743 | } |
| 744 | return &it->second; |
| 745 | } |
| 746 | |
| 747 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) { |
| 748 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 749 | auto it = phys_dev_map->find(phys); |
| 750 | if (it == phys_dev_map->end()) { |
| 751 | return nullptr; |
| 752 | } |
| 753 | return &it->second; |
| 754 | } |
| 755 | |
| 756 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() { return physical_device_state; } |
| 757 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() const { return physical_device_state; } |
| 758 | |
| 759 | // Return ptr to memory binding for given handle of specified type |
| 760 | template <typename State, typename Result> |
| 761 | static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) { |
| 762 | switch (typed_handle.type) { |
| 763 | case kVulkanObjectTypeImage: |
| 764 | return state->GetImageState(typed_handle.Cast<VkImage>()); |
| 765 | case kVulkanObjectTypeBuffer: |
| 766 | return state->GetBufferState(typed_handle.Cast<VkBuffer>()); |
| 767 | case kVulkanObjectTypeAccelerationStructureNV: |
| 768 | return state->GetAccelerationStructureState(typed_handle.Cast<VkAccelerationStructureNV>()); |
| 769 | default: |
| 770 | break; |
| 771 | } |
| 772 | return nullptr; |
| 773 | } |
| 774 | |
| 775 | const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const { |
| 776 | return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle); |
| 777 | } |
| 778 | |
| 779 | BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) { |
| 780 | return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle); |
| 781 | } |
| 782 | |
| 783 | void ValidationStateTracker::AddMemObjInfo(void *object, const VkDeviceMemory mem, const VkMemoryAllocateInfo *pAllocateInfo) { |
| 784 | assert(object != NULL); |
| 785 | |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 786 | auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize); |
| 787 | 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] | 788 | auto mem_info = memObjMap[mem].get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 789 | |
| 790 | auto dedicated = lvl_find_in_chain<VkMemoryDedicatedAllocateInfoKHR>(pAllocateInfo->pNext); |
| 791 | if (dedicated) { |
| 792 | mem_info->is_dedicated = true; |
| 793 | mem_info->dedicated_buffer = dedicated->buffer; |
| 794 | mem_info->dedicated_image = dedicated->image; |
| 795 | } |
| 796 | auto export_info = lvl_find_in_chain<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext); |
| 797 | if (export_info) { |
| 798 | mem_info->is_export = true; |
| 799 | mem_info->export_handle_type_flags = export_info->handleTypes; |
| 800 | } |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 801 | |
Mark Lobodzinski | 7bda6ed | 2020-07-24 09:57:38 -0600 | [diff] [blame] | 802 | auto alloc_flags = lvl_find_in_chain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext); |
| 803 | if (alloc_flags) { |
| 804 | auto dev_mask = alloc_flags->deviceMask; |
| 805 | if ((dev_mask != 0) && (dev_mask & (dev_mask - 1))) { |
| 806 | mem_info->multi_instance = true; |
| 807 | } |
| 808 | } |
| 809 | 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] | 810 | mem_info->multi_instance |= (((phys_dev_mem_props.memoryHeaps[heap_index].flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT) != 0) && |
| 811 | physical_device_count > 1); |
Mark Lobodzinski | 7bda6ed | 2020-07-24 09:57:38 -0600 | [diff] [blame] | 812 | |
sfricke-samsung | 2306827 | 2020-06-21 14:49:51 -0700 | [diff] [blame] | 813 | // Assumes validation already for only a single import operation in the pNext |
| 814 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 815 | auto win32_import = lvl_find_in_chain<VkImportMemoryWin32HandleInfoKHR>(pAllocateInfo->pNext); |
| 816 | if (win32_import) { |
| 817 | mem_info->is_import = true; |
| 818 | mem_info->import_handle_type_flags = win32_import->handleType; |
| 819 | } |
| 820 | #endif |
| 821 | auto fd_import = lvl_find_in_chain<VkImportMemoryFdInfoKHR>(pAllocateInfo->pNext); |
| 822 | if (fd_import) { |
| 823 | mem_info->is_import = true; |
| 824 | mem_info->import_handle_type_flags = fd_import->handleType; |
| 825 | } |
| 826 | auto host_pointer_import = lvl_find_in_chain<VkImportMemoryHostPointerInfoEXT>(pAllocateInfo->pNext); |
| 827 | if (host_pointer_import) { |
| 828 | mem_info->is_import = true; |
| 829 | mem_info->import_handle_type_flags = host_pointer_import->handleType; |
| 830 | } |
| 831 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 832 | // AHB Import doesn't have handle in the pNext struct |
| 833 | // It should be assumed that all imported AHB can only have the same, single handleType |
| 834 | auto ahb_import = lvl_find_in_chain<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext); |
| 835 | if ((ahb_import) && (ahb_import->buffer != nullptr)) { |
| 836 | mem_info->is_import_ahb = true; |
| 837 | mem_info->is_import = true; |
| 838 | mem_info->import_handle_type_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID; |
| 839 | } |
| 840 | #endif |
sfricke-samsung | edce77a | 2020-07-03 22:35:13 -0700 | [diff] [blame] | 841 | |
| 842 | const VkMemoryType memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex]; |
| 843 | mem_info->unprotected = ((memory_type.propertyFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT) == 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | // Create binding link between given sampler and command buffer node |
| 847 | void ValidationStateTracker::AddCommandBufferBindingSampler(CMD_BUFFER_STATE *cb_node, SAMPLER_STATE *sampler_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 848 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 849 | return; |
| 850 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 851 | AddCommandBufferBinding(sampler_state->cb_bindings, |
| 852 | VulkanTypedHandle(sampler_state->sampler, kVulkanObjectTypeSampler, sampler_state), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | // Create binding link between given image node and command buffer node |
| 856 | void ValidationStateTracker::AddCommandBufferBindingImage(CMD_BUFFER_STATE *cb_node, IMAGE_STATE *image_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 857 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | // Skip validation if this image was created through WSI |
| 861 | if (image_state->create_from_swapchain == VK_NULL_HANDLE) { |
| 862 | // First update cb binding for image |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 863 | if (AddCommandBufferBinding(image_state->cb_bindings, |
| 864 | VulkanTypedHandle(image_state->image, kVulkanObjectTypeImage, image_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 865 | // Now update CB binding in MemObj mini CB list |
| 866 | for (auto mem_binding : image_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 867 | // Now update CBInfo's Mem reference list |
| 868 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 869 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | // Create binding link between given image view node and its image with command buffer node |
| 876 | 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] | 877 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 878 | return; |
| 879 | } |
| 880 | // First add bindings for imageView |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 881 | if (AddCommandBufferBinding(view_state->cb_bindings, |
| 882 | VulkanTypedHandle(view_state->image_view, kVulkanObjectTypeImageView, view_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 883 | // Only need to continue if this is a new item |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 884 | auto image_state = view_state->image_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 885 | // Add bindings for image within imageView |
| 886 | if (image_state) { |
| 887 | AddCommandBufferBindingImage(cb_node, image_state); |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | // Create binding link between given buffer node and command buffer node |
| 893 | void ValidationStateTracker::AddCommandBufferBindingBuffer(CMD_BUFFER_STATE *cb_node, BUFFER_STATE *buffer_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 894 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 895 | return; |
| 896 | } |
| 897 | // First update cb binding for buffer |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 898 | if (AddCommandBufferBinding(buffer_state->cb_bindings, |
| 899 | VulkanTypedHandle(buffer_state->buffer, kVulkanObjectTypeBuffer, buffer_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 900 | // Now update CB binding in MemObj mini CB list |
| 901 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 902 | // Now update CBInfo's Mem reference list |
| 903 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 904 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | // Create binding link between given buffer view node and its buffer with command buffer node |
| 910 | 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] | 911 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 912 | return; |
| 913 | } |
| 914 | // First add bindings for bufferView |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 915 | if (AddCommandBufferBinding(view_state->cb_bindings, |
| 916 | VulkanTypedHandle(view_state->buffer_view, kVulkanObjectTypeBufferView, view_state), cb_node)) { |
| 917 | auto buffer_state = view_state->buffer_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 918 | // Add bindings for buffer within bufferView |
| 919 | if (buffer_state) { |
| 920 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
| 921 | } |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | // Create binding link between given acceleration structure and command buffer node |
| 926 | void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node, |
| 927 | ACCELERATION_STRUCTURE_STATE *as_state) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 928 | if (disabled[command_buffer_state]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 929 | return; |
| 930 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 931 | if (AddCommandBufferBinding( |
| 932 | as_state->cb_bindings, |
| 933 | VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureNV, as_state), cb_node)) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 934 | // Now update CB binding in MemObj mini CB list |
| 935 | for (auto mem_binding : as_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 936 | // Now update CBInfo's Mem reference list |
| 937 | AddCommandBufferBinding(mem_binding->cb_bindings, |
| 938 | VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 943 | // Clear a single object binding from given memory object |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 944 | void ValidationStateTracker::ClearMemoryObjectBinding(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 945 | // This obj is bound to a memory object. Remove the reference to this object in that memory object's list |
| 946 | if (mem_info) { |
| 947 | mem_info->obj_bindings.erase(typed_handle); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | // ClearMemoryObjectBindings clears the binding of objects to memory |
| 952 | // For the given object it pulls the memory bindings and makes sure that the bindings |
| 953 | // no longer refer to the object being cleared. This occurs when objects are destroyed. |
| 954 | void ValidationStateTracker::ClearMemoryObjectBindings(const VulkanTypedHandle &typed_handle) { |
| 955 | BINDABLE *mem_binding = GetObjectMemBinding(typed_handle); |
| 956 | if (mem_binding) { |
| 957 | if (!mem_binding->sparse) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 958 | ClearMemoryObjectBinding(typed_handle, mem_binding->binding.mem_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 959 | } else { // Sparse, clear all bindings |
| 960 | for (auto &sparse_mem_binding : mem_binding->sparse_bindings) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 961 | ClearMemoryObjectBinding(typed_handle, sparse_mem_binding.mem_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | // SetMemBinding is used to establish immutable, non-sparse binding between a single image/buffer object and memory object. |
| 968 | // Corresponding valid usage checks are in ValidateSetMemBinding(). |
| 969 | void ValidationStateTracker::SetMemBinding(VkDeviceMemory mem, BINDABLE *mem_binding, VkDeviceSize memory_offset, |
| 970 | const VulkanTypedHandle &typed_handle) { |
| 971 | assert(mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 972 | |
| 973 | if (mem != VK_NULL_HANDLE) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 974 | mem_binding->binding.mem_state = GetShared<DEVICE_MEMORY_STATE>(mem); |
| 975 | if (mem_binding->binding.mem_state) { |
locke-lunarg | 5f59e78 | 2019-12-19 10:32:23 -0700 | [diff] [blame] | 976 | mem_binding->binding.offset = memory_offset; |
| 977 | mem_binding->binding.size = mem_binding->requirements.size; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 978 | mem_binding->binding.mem_state->obj_bindings.insert(typed_handle); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 979 | // For image objects, make sure default memory state is correctly set |
| 980 | // TODO : What's the best/correct way to handle this? |
| 981 | if (kVulkanObjectTypeImage == typed_handle.type) { |
| 982 | auto const image_state = reinterpret_cast<const IMAGE_STATE *>(mem_binding); |
| 983 | if (image_state) { |
| 984 | VkImageCreateInfo ici = image_state->createInfo; |
| 985 | if (ici.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 986 | // TODO:: More memory state transition stuff. |
| 987 | } |
| 988 | } |
| 989 | } |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 990 | mem_binding->UpdateBoundMemorySet(); // force recreation of cached set |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | // For NULL mem case, clear any previous binding Else... |
| 996 | // Make sure given object is in its object map |
| 997 | // IF a previous binding existed, update binding |
| 998 | // Add reference from objectInfo to memoryInfo |
| 999 | // Add reference off of object's binding info |
| 1000 | // Return VK_TRUE if addition is successful, VK_FALSE otherwise |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1001 | bool ValidationStateTracker::SetSparseMemBinding(const VkDeviceMemory mem, const VkDeviceSize mem_offset, |
| 1002 | const VkDeviceSize mem_size, const VulkanTypedHandle &typed_handle) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1003 | bool skip = VK_FALSE; |
| 1004 | // Handle NULL case separately, just clear previous binding & decrement reference |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1005 | if (mem == VK_NULL_HANDLE) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1006 | // TODO : This should cause the range of the resource to be unbound according to spec |
| 1007 | } else { |
| 1008 | BINDABLE *mem_binding = GetObjectMemBinding(typed_handle); |
| 1009 | assert(mem_binding); |
| 1010 | if (mem_binding) { // Invalid handles are reported by object tracker, but Get returns NULL for them, so avoid SEGV here |
| 1011 | assert(mem_binding->sparse); |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 1012 | MEM_BINDING binding = {GetShared<DEVICE_MEMORY_STATE>(mem), mem_offset, mem_size}; |
| 1013 | if (binding.mem_state) { |
| 1014 | binding.mem_state->obj_bindings.insert(typed_handle); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1015 | // Need to set mem binding for this object |
| 1016 | mem_binding->sparse_bindings.insert(binding); |
| 1017 | mem_binding->UpdateBoundMemorySet(); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | return skip; |
| 1022 | } |
| 1023 | |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1024 | void ValidationStateTracker::UpdateDrawState(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point, |
| 1025 | const char *function) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1026 | auto &state = cb_state->lastBound[bind_point]; |
| 1027 | PIPELINE_STATE *pPipe = state.pipeline_state; |
| 1028 | if (VK_NULL_HANDLE != state.pipeline_layout) { |
| 1029 | for (const auto &set_binding_pair : pPipe->active_slots) { |
| 1030 | uint32_t setIndex = set_binding_pair.first; |
| 1031 | // Pull the set node |
| 1032 | cvdescriptorset::DescriptorSet *descriptor_set = state.per_set[setIndex].bound_descriptor_set; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1033 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1034 | // 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] | 1035 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1036 | // TODO: If recreating the reduced_map here shows up in profilinging, need to find a way of sharing with the |
| 1037 | // Validate pass. Though in the case of "many" descriptors, typically the descriptor count >> binding count |
| 1038 | cvdescriptorset::PrefilterBindRequestMap reduced_map(*descriptor_set, set_binding_pair.second); |
| 1039 | const auto &binding_req_map = reduced_map.FilteredMap(*cb_state, *pPipe); |
| 1040 | |
| 1041 | if (reduced_map.IsManyDescriptors()) { |
| 1042 | // Only update validate binding tags if we meet the "many" criteria in the Prefilter class |
| 1043 | descriptor_set->UpdateValidationCache(*cb_state, *pPipe, binding_req_map); |
| 1044 | } |
| 1045 | |
| 1046 | // We can skip updating the state if "nothing" has changed since the last validation. |
| 1047 | // See CoreChecks::ValidateCmdBufDrawState for more details. |
| 1048 | bool descriptor_set_changed = |
| 1049 | !reduced_map.IsManyDescriptors() || |
| 1050 | // Update if descriptor set (or contents) has changed |
| 1051 | state.per_set[setIndex].validated_set != descriptor_set || |
| 1052 | state.per_set[setIndex].validated_set_change_count != descriptor_set->GetChangeCount() || |
| 1053 | (!disabled[image_layout_validation] && |
| 1054 | state.per_set[setIndex].validated_set_image_layout_change_count != cb_state->image_layout_change_count); |
| 1055 | bool need_update = descriptor_set_changed || |
| 1056 | // Update if previous bindingReqMap doesn't include new bindingReqMap |
| 1057 | !std::includes(state.per_set[setIndex].validated_set_binding_req_map.begin(), |
| 1058 | state.per_set[setIndex].validated_set_binding_req_map.end(), binding_req_map.begin(), |
| 1059 | binding_req_map.end()); |
| 1060 | |
| 1061 | if (need_update) { |
| 1062 | // Bind this set and its active descriptor resources to the command buffer |
| 1063 | if (!descriptor_set_changed && reduced_map.IsManyDescriptors()) { |
| 1064 | // Only record the bindings that haven't already been recorded |
| 1065 | BindingReqMap delta_reqs; |
| 1066 | std::set_difference(binding_req_map.begin(), binding_req_map.end(), |
| 1067 | state.per_set[setIndex].validated_set_binding_req_map.begin(), |
| 1068 | state.per_set[setIndex].validated_set_binding_req_map.end(), |
| 1069 | std::inserter(delta_reqs, delta_reqs.begin())); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1070 | descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pPipe, delta_reqs, function); |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1071 | } else { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1072 | descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pPipe, binding_req_map, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1073 | } |
| 1074 | |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1075 | state.per_set[setIndex].validated_set = descriptor_set; |
| 1076 | state.per_set[setIndex].validated_set_change_count = descriptor_set->GetChangeCount(); |
| 1077 | state.per_set[setIndex].validated_set_image_layout_change_count = cb_state->image_layout_change_count; |
| 1078 | if (reduced_map.IsManyDescriptors()) { |
| 1079 | // Check whether old == new before assigning, the equality check is much cheaper than |
| 1080 | // freeing and reallocating the map. |
| 1081 | if (state.per_set[setIndex].validated_set_binding_req_map != set_binding_pair.second) { |
| 1082 | state.per_set[setIndex].validated_set_binding_req_map = set_binding_pair.second; |
Jeff Bolz | 5630894 | 2019-10-06 22:05:23 -0500 | [diff] [blame] | 1083 | } |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1084 | } else { |
| 1085 | state.per_set[setIndex].validated_set_binding_req_map = BindingReqMap(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | if (!pPipe->vertex_binding_descriptions_.empty()) { |
| 1091 | cb_state->vertex_buffer_used = true; |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // Remove set from setMap and delete the set |
| 1096 | void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 1097 | descriptor_set->destroyed = true; |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1098 | const VulkanTypedHandle obj_struct(descriptor_set->GetSet(), kVulkanObjectTypeDescriptorSet); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1099 | // Any bound cmd buffers are now invalid |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1100 | InvalidateCommandBuffers(descriptor_set->cb_bindings, obj_struct); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1101 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1102 | setMap.erase(descriptor_set->GetSet()); |
| 1103 | } |
| 1104 | |
| 1105 | // Free all DS Pools including their Sets & related sub-structs |
| 1106 | // NOTE : Calls to this function should be wrapped in mutex |
| 1107 | void ValidationStateTracker::DeleteDescriptorSetPools() { |
| 1108 | for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) { |
| 1109 | // Remove this pools' sets from setMap and delete them |
| 1110 | for (auto ds : ii->second->sets) { |
| 1111 | FreeDescriptorSet(ds); |
| 1112 | } |
| 1113 | ii->second->sets.clear(); |
| 1114 | ii = descriptorPoolMap.erase(ii); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | // For given object struct return a ptr of BASE_NODE type for its wrapping struct |
| 1119 | BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1120 | if (object_struct.node) { |
| 1121 | #ifdef _DEBUG |
| 1122 | // assert that lookup would find the same object |
| 1123 | VulkanTypedHandle other = object_struct; |
| 1124 | other.node = nullptr; |
| 1125 | assert(object_struct.node == GetStateStructPtrFromObject(other)); |
| 1126 | #endif |
| 1127 | return object_struct.node; |
| 1128 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1129 | BASE_NODE *base_ptr = nullptr; |
| 1130 | switch (object_struct.type) { |
| 1131 | case kVulkanObjectTypeDescriptorSet: { |
| 1132 | base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>()); |
| 1133 | break; |
| 1134 | } |
| 1135 | case kVulkanObjectTypeSampler: { |
| 1136 | base_ptr = GetSamplerState(object_struct.Cast<VkSampler>()); |
| 1137 | break; |
| 1138 | } |
| 1139 | case kVulkanObjectTypeQueryPool: { |
| 1140 | base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>()); |
| 1141 | break; |
| 1142 | } |
| 1143 | case kVulkanObjectTypePipeline: { |
| 1144 | base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>()); |
| 1145 | break; |
| 1146 | } |
| 1147 | case kVulkanObjectTypeBuffer: { |
| 1148 | base_ptr = GetBufferState(object_struct.Cast<VkBuffer>()); |
| 1149 | break; |
| 1150 | } |
| 1151 | case kVulkanObjectTypeBufferView: { |
| 1152 | base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>()); |
| 1153 | break; |
| 1154 | } |
| 1155 | case kVulkanObjectTypeImage: { |
| 1156 | base_ptr = GetImageState(object_struct.Cast<VkImage>()); |
| 1157 | break; |
| 1158 | } |
| 1159 | case kVulkanObjectTypeImageView: { |
| 1160 | base_ptr = GetImageViewState(object_struct.Cast<VkImageView>()); |
| 1161 | break; |
| 1162 | } |
| 1163 | case kVulkanObjectTypeEvent: { |
| 1164 | base_ptr = GetEventState(object_struct.Cast<VkEvent>()); |
| 1165 | break; |
| 1166 | } |
| 1167 | case kVulkanObjectTypeDescriptorPool: { |
| 1168 | base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>()); |
| 1169 | break; |
| 1170 | } |
| 1171 | case kVulkanObjectTypeCommandPool: { |
| 1172 | base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>()); |
| 1173 | break; |
| 1174 | } |
| 1175 | case kVulkanObjectTypeFramebuffer: { |
| 1176 | base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>()); |
| 1177 | break; |
| 1178 | } |
| 1179 | case kVulkanObjectTypeRenderPass: { |
| 1180 | base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>()); |
| 1181 | break; |
| 1182 | } |
| 1183 | case kVulkanObjectTypeDeviceMemory: { |
| 1184 | base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>()); |
| 1185 | break; |
| 1186 | } |
| 1187 | case kVulkanObjectTypeAccelerationStructureNV: { |
| 1188 | base_ptr = GetAccelerationStructureState(object_struct.Cast<VkAccelerationStructureNV>()); |
| 1189 | break; |
| 1190 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1191 | case kVulkanObjectTypeUnknown: |
| 1192 | // This can happen if an element of the object_bindings vector has been |
| 1193 | // zeroed out, after an object is destroyed. |
| 1194 | break; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1195 | default: |
| 1196 | // TODO : Any other objects to be handled here? |
| 1197 | assert(0); |
| 1198 | break; |
| 1199 | } |
| 1200 | return base_ptr; |
| 1201 | } |
| 1202 | |
sfricke-samsung | bf1a2ed | 2020-06-14 23:31:00 -0700 | [diff] [blame] | 1203 | // Gets union of all features defined by Potential Format Features |
| 1204 | // 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] | 1205 | VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const { |
| 1206 | VkFormatFeatureFlags format_features = 0; |
| 1207 | |
| 1208 | if (format != VK_FORMAT_UNDEFINED) { |
| 1209 | VkFormatProperties format_properties; |
| 1210 | DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties); |
| 1211 | format_features |= format_properties.linearTilingFeatures; |
| 1212 | format_features |= format_properties.optimalTilingFeatures; |
| 1213 | if (device_extensions.vk_ext_image_drm_format_modifier) { |
| 1214 | // VK_KHR_get_physical_device_properties2 is required in this case |
| 1215 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; |
| 1216 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 1217 | nullptr}; |
| 1218 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 1219 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
| 1220 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
| 1221 | format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | return format_features; |
| 1227 | } |
| 1228 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1229 | // Tie the VulkanTypedHandle to the cmd buffer which includes: |
| 1230 | // Add object_binding to cmd buffer |
| 1231 | // Add cb_binding to object |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1232 | 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] | 1233 | const VulkanTypedHandle &obj, CMD_BUFFER_STATE *cb_node) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 1234 | if (disabled[command_buffer_state]) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1235 | return false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1236 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1237 | // Insert the cb_binding with a default 'index' of -1. Then push the obj into the object_bindings |
| 1238 | // vector, and update cb_bindings[cb_node] with the index of that element of the vector. |
| 1239 | auto inserted = cb_bindings.insert({cb_node, -1}); |
| 1240 | if (inserted.second) { |
| 1241 | cb_node->object_bindings.push_back(obj); |
| 1242 | inserted.first->second = (int)cb_node->object_bindings.size() - 1; |
| 1243 | return true; |
| 1244 | } |
| 1245 | return false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | // For a given object, if cb_node is in that objects cb_bindings, remove cb_node |
| 1249 | void ValidationStateTracker::RemoveCommandBufferBinding(VulkanTypedHandle const &object, CMD_BUFFER_STATE *cb_node) { |
| 1250 | BASE_NODE *base_obj = GetStateStructPtrFromObject(object); |
| 1251 | if (base_obj) base_obj->cb_bindings.erase(cb_node); |
| 1252 | } |
| 1253 | |
| 1254 | // Reset the command buffer state |
| 1255 | // Maintain the createInfo and set state to CB_NEW, but clear all other state |
| 1256 | void ValidationStateTracker::ResetCommandBufferState(const VkCommandBuffer cb) { |
| 1257 | CMD_BUFFER_STATE *pCB = GetCBState(cb); |
| 1258 | if (pCB) { |
| 1259 | pCB->in_use.store(0); |
| 1260 | // Reset CB state (note that createInfo is not cleared) |
| 1261 | pCB->commandBuffer = cb; |
| 1262 | memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 1263 | memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo)); |
| 1264 | pCB->hasDrawCmd = false; |
| 1265 | pCB->hasTraceRaysCmd = false; |
| 1266 | pCB->hasBuildAccelerationStructureCmd = false; |
| 1267 | pCB->hasDispatchCmd = false; |
| 1268 | pCB->state = CB_NEW; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1269 | pCB->commandCount = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1270 | pCB->submitCount = 0; |
| 1271 | pCB->image_layout_change_count = 1; // Start at 1. 0 is insert value for validation cache versions, s.t. new == dirty |
| 1272 | pCB->status = 0; |
| 1273 | pCB->static_status = 0; |
| 1274 | pCB->viewportMask = 0; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1275 | pCB->viewportWithCountMask = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1276 | pCB->scissorMask = 0; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1277 | pCB->scissorWithCountMask = 0; |
| 1278 | pCB->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1279 | |
| 1280 | for (auto &item : pCB->lastBound) { |
| 1281 | item.second.reset(); |
| 1282 | } |
| 1283 | |
Tony-LunarG | 61e7c0c | 2020-03-03 16:09:11 -0700 | [diff] [blame] | 1284 | pCB->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1285 | pCB->activeRenderPass = nullptr; |
| 1286 | pCB->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE; |
| 1287 | pCB->activeSubpass = 0; |
| 1288 | pCB->broken_bindings.clear(); |
| 1289 | pCB->waitedEvents.clear(); |
| 1290 | pCB->events.clear(); |
| 1291 | pCB->writeEventsBeforeWait.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1292 | pCB->activeQueries.clear(); |
| 1293 | pCB->startedQueries.clear(); |
| 1294 | pCB->image_layout_map.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1295 | pCB->current_vertex_buffer_binding_info.vertex_buffer_bindings.clear(); |
| 1296 | pCB->vertex_buffer_used = false; |
| 1297 | pCB->primaryCommandBuffer = VK_NULL_HANDLE; |
| 1298 | // If secondary, invalidate any primary command buffer that may call us. |
| 1299 | if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1300 | InvalidateLinkedCommandBuffers(pCB->linkedCommandBuffers, VulkanTypedHandle(cb, kVulkanObjectTypeCommandBuffer)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | // Remove reverse command buffer links. |
| 1304 | for (auto pSubCB : pCB->linkedCommandBuffers) { |
| 1305 | pSubCB->linkedCommandBuffers.erase(pCB); |
| 1306 | } |
| 1307 | pCB->linkedCommandBuffers.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1308 | pCB->queue_submit_functions.clear(); |
| 1309 | pCB->cmd_execute_commands_functions.clear(); |
| 1310 | pCB->eventUpdates.clear(); |
| 1311 | pCB->queryUpdates.clear(); |
| 1312 | |
| 1313 | // Remove object bindings |
| 1314 | for (const auto &obj : pCB->object_bindings) { |
| 1315 | RemoveCommandBufferBinding(obj, pCB); |
| 1316 | } |
| 1317 | pCB->object_bindings.clear(); |
| 1318 | // Remove this cmdBuffer's reference from each FrameBuffer's CB ref list |
| 1319 | for (auto framebuffer : pCB->framebuffers) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 1320 | framebuffer->cb_bindings.erase(pCB); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1321 | } |
| 1322 | pCB->framebuffers.clear(); |
| 1323 | pCB->activeFramebuffer = VK_NULL_HANDLE; |
| 1324 | memset(&pCB->index_buffer_binding, 0, sizeof(pCB->index_buffer_binding)); |
| 1325 | |
| 1326 | pCB->qfo_transfer_image_barriers.Reset(); |
| 1327 | pCB->qfo_transfer_buffer_barriers.Reset(); |
| 1328 | |
| 1329 | // Clean up the label data |
| 1330 | ResetCmdDebugUtilsLabel(report_data, pCB->commandBuffer); |
| 1331 | pCB->debug_label.Reset(); |
locke-g | b3ce08f | 2019-09-30 12:30:56 -0600 | [diff] [blame] | 1332 | pCB->validate_descriptorsets_in_queuesubmit.clear(); |
Attilio Provenzano | 02859b2 | 2020-02-27 14:17:28 +0000 | [diff] [blame] | 1333 | |
| 1334 | // Best practices info |
| 1335 | pCB->small_indexed_draw_call_count = 0; |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 1336 | |
| 1337 | pCB->transform_feedback_active = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1338 | } |
| 1339 | if (command_buffer_reset_callback) { |
| 1340 | (*command_buffer_reset_callback)(cb); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 1345 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, |
| 1346 | VkResult result) { |
| 1347 | if (VK_SUCCESS != result) return; |
| 1348 | |
| 1349 | const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures; |
| 1350 | if (nullptr == enabled_features_found) { |
| 1351 | const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext); |
| 1352 | if (features2) { |
| 1353 | enabled_features_found = &(features2->features); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 1358 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type); |
| 1359 | ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data); |
| 1360 | |
| 1361 | if (nullptr == enabled_features_found) { |
| 1362 | state_tracker->enabled_features.core = {}; |
| 1363 | } else { |
| 1364 | state_tracker->enabled_features.core = *enabled_features_found; |
| 1365 | } |
| 1366 | |
| 1367 | // Make sure that queue_family_properties are obtained for this device's physical_device, even if the app has not |
| 1368 | // previously set them through an explicit API call. |
| 1369 | uint32_t count; |
| 1370 | auto pd_state = GetPhysicalDeviceState(gpu); |
| 1371 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr); |
| 1372 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 1373 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, &pd_state->queue_family_properties[0]); |
| 1374 | // Save local link to this device's physical device state |
| 1375 | state_tracker->physical_device_state = pd_state; |
| 1376 | |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1377 | const auto *vulkan_12_features = lvl_find_in_chain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext); |
| 1378 | if (vulkan_12_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1379 | state_tracker->enabled_features.core12 = *vulkan_12_features; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1380 | } else { |
sfricke-samsung | 27c7072 | 2020-05-02 08:42:39 -0700 | [diff] [blame] | 1381 | // Set Extension Feature Aliases to false as there is no struct to check |
| 1382 | state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE; |
| 1383 | state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE; |
| 1384 | state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE; |
| 1385 | state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE; |
| 1386 | state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE; |
| 1387 | state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE; |
| 1388 | |
| 1389 | // 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] | 1390 | |
| 1391 | const auto *eight_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext); |
| 1392 | if (eight_bit_storage_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1393 | state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess; |
| 1394 | state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess = |
| 1395 | eight_bit_storage_features->uniformAndStorageBuffer8BitAccess; |
| 1396 | state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | const auto *float16_int8_features = lvl_find_in_chain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext); |
| 1400 | if (float16_int8_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1401 | state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16; |
| 1402 | state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | const auto *descriptor_indexing_features = |
| 1406 | lvl_find_in_chain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext); |
| 1407 | if (descriptor_indexing_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1408 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing = |
| 1409 | descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing; |
| 1410 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing = |
| 1411 | descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing; |
| 1412 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing = |
| 1413 | descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing; |
| 1414 | state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing = |
| 1415 | descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing; |
| 1416 | state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing = |
| 1417 | descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing; |
| 1418 | state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing = |
| 1419 | descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing; |
| 1420 | state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing = |
| 1421 | descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing; |
| 1422 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing = |
| 1423 | descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing; |
| 1424 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing = |
| 1425 | descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing; |
| 1426 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing = |
| 1427 | descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing; |
| 1428 | state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind = |
| 1429 | descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind; |
| 1430 | state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind = |
| 1431 | descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind; |
| 1432 | state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind = |
| 1433 | descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind; |
| 1434 | state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind = |
| 1435 | descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind; |
| 1436 | state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind = |
| 1437 | descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind; |
| 1438 | state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind = |
| 1439 | descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind; |
| 1440 | state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending = |
| 1441 | descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending; |
| 1442 | state_tracker->enabled_features.core12.descriptorBindingPartiallyBound = |
| 1443 | descriptor_indexing_features->descriptorBindingPartiallyBound; |
| 1444 | state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount = |
| 1445 | descriptor_indexing_features->descriptorBindingVariableDescriptorCount; |
| 1446 | state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1449 | 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] | 1450 | if (scalar_block_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1451 | state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | const auto *imageless_framebuffer_features = |
| 1455 | lvl_find_in_chain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext); |
| 1456 | if (imageless_framebuffer_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1457 | state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | const auto *uniform_buffer_standard_layout_features = |
| 1461 | lvl_find_in_chain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext); |
| 1462 | if (uniform_buffer_standard_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1463 | state_tracker->enabled_features.core12.uniformBufferStandardLayout = |
| 1464 | uniform_buffer_standard_layout_features->uniformBufferStandardLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | const auto *subgroup_extended_types_features = |
| 1468 | lvl_find_in_chain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext); |
| 1469 | if (subgroup_extended_types_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1470 | state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes = |
| 1471 | subgroup_extended_types_features->shaderSubgroupExtendedTypes; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | const auto *separate_depth_stencil_layouts_features = |
| 1475 | lvl_find_in_chain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext); |
| 1476 | if (separate_depth_stencil_layouts_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1477 | state_tracker->enabled_features.core12.separateDepthStencilLayouts = |
| 1478 | separate_depth_stencil_layouts_features->separateDepthStencilLayouts; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | const auto *host_query_reset_features = lvl_find_in_chain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext); |
| 1482 | if (host_query_reset_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1483 | state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1486 | const auto *timeline_semaphore_features = lvl_find_in_chain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1487 | if (timeline_semaphore_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1488 | state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | const auto *buffer_device_address = lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext); |
| 1492 | if (buffer_device_address) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1493 | state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress; |
| 1494 | state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay = |
| 1495 | buffer_device_address->bufferDeviceAddressCaptureReplay; |
| 1496 | state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice = |
| 1497 | buffer_device_address->bufferDeviceAddressMultiDevice; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | const auto *vulkan_11_features = lvl_find_in_chain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext); |
| 1502 | if (vulkan_11_features) { |
| 1503 | state_tracker->enabled_features.core11 = *vulkan_11_features; |
| 1504 | } else { |
| 1505 | // These structs are only allowed in pNext chain if there is no kPhysicalDeviceVulkan11Features |
| 1506 | |
| 1507 | const auto *sixteen_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext); |
| 1508 | if (sixteen_bit_storage_features) { |
| 1509 | state_tracker->enabled_features.core11.storageBuffer16BitAccess = |
| 1510 | sixteen_bit_storage_features->storageBuffer16BitAccess; |
| 1511 | state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess = |
| 1512 | sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess; |
| 1513 | state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16; |
| 1514 | state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16; |
| 1515 | } |
| 1516 | |
| 1517 | const auto *multiview_features = lvl_find_in_chain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
| 1518 | if (multiview_features) { |
| 1519 | state_tracker->enabled_features.core11.multiview = multiview_features->multiview; |
| 1520 | state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader; |
| 1521 | state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader; |
| 1522 | } |
| 1523 | |
| 1524 | const auto *variable_pointers_features = lvl_find_in_chain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext); |
| 1525 | if (variable_pointers_features) { |
| 1526 | state_tracker->enabled_features.core11.variablePointersStorageBuffer = |
| 1527 | variable_pointers_features->variablePointersStorageBuffer; |
| 1528 | state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers; |
| 1529 | } |
| 1530 | |
| 1531 | const auto *protected_memory_features = lvl_find_in_chain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext); |
| 1532 | if (protected_memory_features) { |
| 1533 | state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory; |
| 1534 | } |
| 1535 | |
| 1536 | const auto *ycbcr_conversion_features = |
| 1537 | lvl_find_in_chain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext); |
| 1538 | if (ycbcr_conversion_features) { |
| 1539 | state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion; |
| 1540 | } |
| 1541 | |
| 1542 | const auto *shader_draw_parameters_features = |
| 1543 | lvl_find_in_chain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext); |
| 1544 | if (shader_draw_parameters_features) { |
| 1545 | state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1549 | const auto *device_group_ci = lvl_find_in_chain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext); |
Tony-LunarG | ca4891a | 2020-08-10 15:46:46 -0600 | [diff] [blame] | 1550 | if (device_group_ci) { |
| 1551 | state_tracker->physical_device_count = device_group_ci->physicalDeviceCount; |
| 1552 | state_tracker->device_group_create_info = *device_group_ci; |
| 1553 | } else { |
| 1554 | state_tracker->physical_device_count = 1; |
| 1555 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1556 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1557 | const auto *exclusive_scissor_features = lvl_find_in_chain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext); |
| 1558 | if (exclusive_scissor_features) { |
| 1559 | state_tracker->enabled_features.exclusive_scissor = *exclusive_scissor_features; |
| 1560 | } |
| 1561 | |
| 1562 | const auto *shading_rate_image_features = lvl_find_in_chain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext); |
| 1563 | if (shading_rate_image_features) { |
| 1564 | state_tracker->enabled_features.shading_rate_image = *shading_rate_image_features; |
| 1565 | } |
| 1566 | |
| 1567 | const auto *mesh_shader_features = lvl_find_in_chain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext); |
| 1568 | if (mesh_shader_features) { |
| 1569 | state_tracker->enabled_features.mesh_shader = *mesh_shader_features; |
| 1570 | } |
| 1571 | |
| 1572 | const auto *inline_uniform_block_features = |
| 1573 | lvl_find_in_chain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext); |
| 1574 | if (inline_uniform_block_features) { |
| 1575 | state_tracker->enabled_features.inline_uniform_block = *inline_uniform_block_features; |
| 1576 | } |
| 1577 | |
| 1578 | const auto *transform_feedback_features = lvl_find_in_chain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext); |
| 1579 | if (transform_feedback_features) { |
| 1580 | state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features; |
| 1581 | } |
| 1582 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1583 | const auto *vtx_attrib_div_features = lvl_find_in_chain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext); |
| 1584 | if (vtx_attrib_div_features) { |
| 1585 | state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features; |
| 1586 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1587 | |
Jeff Bolz | 4563f2a | 2019-12-10 13:30:30 -0600 | [diff] [blame] | 1588 | const auto *buffer_device_address_ext = lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext); |
| 1589 | if (buffer_device_address_ext) { |
Jeff Bolz | 33fc672 | 2020-03-31 12:58:16 -0500 | [diff] [blame] | 1590 | state_tracker->enabled_features.buffer_device_address_ext = *buffer_device_address_ext; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | const auto *cooperative_matrix_features = lvl_find_in_chain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext); |
| 1594 | if (cooperative_matrix_features) { |
| 1595 | state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features; |
| 1596 | } |
| 1597 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1598 | const auto *compute_shader_derivatives_features = |
| 1599 | lvl_find_in_chain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext); |
| 1600 | if (compute_shader_derivatives_features) { |
| 1601 | state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features; |
| 1602 | } |
| 1603 | |
| 1604 | const auto *fragment_shader_barycentric_features = |
| 1605 | lvl_find_in_chain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext); |
| 1606 | if (fragment_shader_barycentric_features) { |
| 1607 | state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features; |
| 1608 | } |
| 1609 | |
| 1610 | const auto *shader_image_footprint_features = |
| 1611 | lvl_find_in_chain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext); |
| 1612 | if (shader_image_footprint_features) { |
| 1613 | state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features; |
| 1614 | } |
| 1615 | |
| 1616 | const auto *fragment_shader_interlock_features = |
| 1617 | lvl_find_in_chain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext); |
| 1618 | if (fragment_shader_interlock_features) { |
| 1619 | state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features; |
| 1620 | } |
| 1621 | |
| 1622 | const auto *demote_to_helper_invocation_features = |
| 1623 | lvl_find_in_chain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext); |
| 1624 | if (demote_to_helper_invocation_features) { |
| 1625 | state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features; |
| 1626 | } |
| 1627 | |
| 1628 | const auto *texel_buffer_alignment_features = |
| 1629 | lvl_find_in_chain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext); |
| 1630 | if (texel_buffer_alignment_features) { |
| 1631 | state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features; |
| 1632 | } |
| 1633 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1634 | const auto *pipeline_exe_props_features = |
| 1635 | lvl_find_in_chain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext); |
| 1636 | if (pipeline_exe_props_features) { |
| 1637 | state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features; |
| 1638 | } |
| 1639 | |
Jeff Bolz | 82f854d | 2019-09-17 14:56:47 -0500 | [diff] [blame] | 1640 | const auto *dedicated_allocation_image_aliasing_features = |
| 1641 | lvl_find_in_chain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext); |
| 1642 | if (dedicated_allocation_image_aliasing_features) { |
| 1643 | state_tracker->enabled_features.dedicated_allocation_image_aliasing_features = |
| 1644 | *dedicated_allocation_image_aliasing_features; |
| 1645 | } |
| 1646 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1647 | const auto *performance_query_features = lvl_find_in_chain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext); |
| 1648 | if (performance_query_features) { |
| 1649 | state_tracker->enabled_features.performance_query_features = *performance_query_features; |
| 1650 | } |
| 1651 | |
Tobias Hector | 782bcde | 2019-11-28 16:19:42 +0000 | [diff] [blame] | 1652 | const auto *device_coherent_memory_features = lvl_find_in_chain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext); |
| 1653 | if (device_coherent_memory_features) { |
| 1654 | state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features; |
| 1655 | } |
| 1656 | |
sfricke-samsung | cead080 | 2020-01-30 22:20:10 -0800 | [diff] [blame] | 1657 | const auto *ycbcr_image_array_features = lvl_find_in_chain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext); |
| 1658 | if (ycbcr_image_array_features) { |
| 1659 | state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features; |
| 1660 | } |
| 1661 | |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 1662 | const auto *ray_tracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(pCreateInfo->pNext); |
| 1663 | if (ray_tracing_features) { |
| 1664 | state_tracker->enabled_features.ray_tracing_features = *ray_tracing_features; |
| 1665 | } |
| 1666 | |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 1667 | const auto *robustness2_features = lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext); |
| 1668 | if (robustness2_features) { |
| 1669 | state_tracker->enabled_features.robustness2_features = *robustness2_features; |
| 1670 | } |
| 1671 | |
janharaldfredriksen-arm | 3b79377 | 2020-05-12 18:55:53 +0200 | [diff] [blame] | 1672 | const auto *fragment_density_map_features = |
| 1673 | lvl_find_in_chain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext); |
| 1674 | if (fragment_density_map_features) { |
| 1675 | state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features; |
| 1676 | } |
| 1677 | |
janharaldfredriksen-arm | 36e1757 | 2020-07-07 13:59:28 +0200 | [diff] [blame] | 1678 | const auto *fragment_density_map_features2 = |
| 1679 | lvl_find_in_chain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext); |
| 1680 | if (fragment_density_map_features2) { |
| 1681 | state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2; |
| 1682 | } |
| 1683 | |
sfricke-samsung | 0c4a06f | 2020-06-27 01:24:32 -0700 | [diff] [blame] | 1684 | const auto *astc_decode_features = lvl_find_in_chain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext); |
| 1685 | if (astc_decode_features) { |
| 1686 | state_tracker->enabled_features.astc_decode_features = *astc_decode_features; |
| 1687 | } |
| 1688 | |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 1689 | const auto *custom_border_color_features = lvl_find_in_chain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext); |
| 1690 | if (custom_border_color_features) { |
| 1691 | state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features; |
| 1692 | } |
| 1693 | |
sfricke-samsung | fd661d6 | 2020-05-16 00:57:27 -0700 | [diff] [blame] | 1694 | const auto *pipeline_creation_cache_control_features = |
| 1695 | lvl_find_in_chain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext); |
| 1696 | if (pipeline_creation_cache_control_features) { |
| 1697 | state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features; |
| 1698 | } |
| 1699 | |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1700 | const auto *extended_dynamic_state_features = |
| 1701 | lvl_find_in_chain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext); |
| 1702 | if (extended_dynamic_state_features) { |
| 1703 | state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features; |
| 1704 | } |
| 1705 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1706 | // Store physical device properties and physical device mem limits into CoreChecks structs |
| 1707 | DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props); |
| 1708 | DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1709 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 1710 | &state_tracker->phys_dev_props_core11); |
| 1711 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 1712 | &state_tracker->phys_dev_props_core12); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1713 | |
| 1714 | const auto &dev_ext = state_tracker->device_extensions; |
| 1715 | auto *phys_dev_props = &state_tracker->phys_dev_ext_props; |
| 1716 | |
| 1717 | if (dev_ext.vk_khr_push_descriptor) { |
| 1718 | // Get the needed push_descriptor limits |
| 1719 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor_prop; |
| 1720 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &push_descriptor_prop); |
| 1721 | phys_dev_props->max_push_descriptors = push_descriptor_prop.maxPushDescriptors; |
| 1722 | } |
| 1723 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1724 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_ext_descriptor_indexing) { |
| 1725 | VkPhysicalDeviceDescriptorIndexingPropertiesEXT descriptor_indexing_prop; |
| 1726 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop); |
| 1727 | state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools = |
| 1728 | descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools; |
| 1729 | state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative = |
| 1730 | descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative; |
| 1731 | state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative = |
| 1732 | descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative; |
| 1733 | state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative = |
| 1734 | descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative; |
| 1735 | state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative = |
| 1736 | descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative; |
| 1737 | state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative = |
| 1738 | descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative; |
| 1739 | state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind = |
| 1740 | descriptor_indexing_prop.robustBufferAccessUpdateAfterBind; |
| 1741 | state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod; |
| 1742 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers = |
| 1743 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers; |
| 1744 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers = |
| 1745 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers; |
| 1746 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers = |
| 1747 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers; |
| 1748 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages = |
| 1749 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages; |
| 1750 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages = |
| 1751 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages; |
| 1752 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments = |
| 1753 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments; |
| 1754 | state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources = |
| 1755 | descriptor_indexing_prop.maxPerStageUpdateAfterBindResources; |
| 1756 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers = |
| 1757 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers; |
| 1758 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers = |
| 1759 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers; |
| 1760 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = |
| 1761 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic; |
| 1762 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers = |
| 1763 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers; |
| 1764 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = |
| 1765 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic; |
| 1766 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages = |
| 1767 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages; |
| 1768 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages = |
| 1769 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages; |
| 1770 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments = |
| 1771 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments; |
| 1772 | } |
| 1773 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1774 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props); |
| 1775 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props); |
| 1776 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props); |
| 1777 | 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] | 1778 | |
| 1779 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_depth_stencil_resolve) { |
| 1780 | VkPhysicalDeviceDepthStencilResolvePropertiesKHR depth_stencil_resolve_props; |
| 1781 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props); |
| 1782 | state_tracker->phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes; |
| 1783 | state_tracker->phys_dev_props_core12.supportedStencilResolveModes = |
| 1784 | depth_stencil_resolve_props.supportedStencilResolveModes; |
| 1785 | state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone; |
| 1786 | state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve; |
| 1787 | } |
| 1788 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1789 | 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] | 1790 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV); |
| 1791 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing, &phys_dev_props->ray_tracing_propsKHR); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1792 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props); |
| 1793 | 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] | 1794 | 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] | 1795 | 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] | 1796 | 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] | 1797 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1798 | |
| 1799 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_timeline_semaphore) { |
| 1800 | VkPhysicalDeviceTimelineSemaphorePropertiesKHR timeline_semaphore_props; |
| 1801 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props); |
| 1802 | state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference = |
| 1803 | timeline_semaphore_props.maxTimelineSemaphoreValueDifference; |
| 1804 | } |
| 1805 | |
| 1806 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_shader_float_controls) { |
| 1807 | VkPhysicalDeviceFloatControlsPropertiesKHR float_controls_props; |
| 1808 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props); |
| 1809 | state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence; |
| 1810 | state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence; |
| 1811 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 = |
| 1812 | float_controls_props.shaderSignedZeroInfNanPreserveFloat16; |
| 1813 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 = |
| 1814 | float_controls_props.shaderSignedZeroInfNanPreserveFloat32; |
| 1815 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 = |
| 1816 | float_controls_props.shaderSignedZeroInfNanPreserveFloat64; |
| 1817 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16; |
| 1818 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32; |
| 1819 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64; |
| 1820 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16; |
| 1821 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32; |
| 1822 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64; |
| 1823 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16; |
| 1824 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32; |
| 1825 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64; |
| 1826 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16; |
| 1827 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32; |
| 1828 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64; |
| 1829 | } |
Mark Lobodzinski | e4a2b7f | 2019-12-20 12:51:30 -0700 | [diff] [blame] | 1830 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1831 | if (state_tracker->device_extensions.vk_nv_cooperative_matrix) { |
| 1832 | // Get the needed cooperative_matrix properties |
| 1833 | auto cooperative_matrix_props = lvl_init_struct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>(); |
| 1834 | auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&cooperative_matrix_props); |
| 1835 | instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2); |
| 1836 | state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props; |
| 1837 | |
| 1838 | uint32_t numCooperativeMatrixProperties = 0; |
| 1839 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &numCooperativeMatrixProperties, NULL); |
| 1840 | state_tracker->cooperative_matrix_properties.resize(numCooperativeMatrixProperties, |
| 1841 | lvl_init_struct<VkCooperativeMatrixPropertiesNV>()); |
| 1842 | |
| 1843 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &numCooperativeMatrixProperties, |
| 1844 | state_tracker->cooperative_matrix_properties.data()); |
| 1845 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1846 | 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] | 1847 | // Get the needed subgroup limits |
| 1848 | auto subgroup_prop = lvl_init_struct<VkPhysicalDeviceSubgroupProperties>(); |
| 1849 | auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&subgroup_prop); |
| 1850 | instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2); |
| 1851 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1852 | state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize; |
| 1853 | state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages; |
| 1854 | state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations; |
| 1855 | state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | // Store queue family data |
| 1859 | if (pCreateInfo->pQueueCreateInfos != nullptr) { |
| 1860 | for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) { |
sfricke-samsung | 590ae1e | 2020-04-25 01:18:05 -0700 | [diff] [blame] | 1861 | const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1862 | state_tracker->queue_family_index_map.insert( |
sfricke-samsung | 590ae1e | 2020-04-25 01:18:05 -0700 | [diff] [blame] | 1863 | std::make_pair(queue_create_info.queueFamilyIndex, queue_create_info.queueCount)); |
| 1864 | state_tracker->queue_family_create_flags_map.insert( |
| 1865 | std::make_pair(queue_create_info.queueFamilyIndex, queue_create_info.flags)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 1871 | if (!device) return; |
| 1872 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1873 | // Reset all command buffers before destroying them, to unlink object_bindings. |
| 1874 | for (auto &commandBuffer : commandBufferMap) { |
| 1875 | ResetCommandBufferState(commandBuffer.first); |
| 1876 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1877 | pipelineMap.clear(); |
| 1878 | renderPassMap.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1879 | commandBufferMap.clear(); |
| 1880 | |
| 1881 | // This will also delete all sets in the pool & remove them from setMap |
| 1882 | DeleteDescriptorSetPools(); |
| 1883 | // All sets should be removed |
| 1884 | assert(setMap.empty()); |
| 1885 | descriptorSetLayoutMap.clear(); |
| 1886 | imageViewMap.clear(); |
| 1887 | imageMap.clear(); |
| 1888 | bufferViewMap.clear(); |
| 1889 | bufferMap.clear(); |
| 1890 | // Queues persist until device is destroyed |
| 1891 | queueMap.clear(); |
| 1892 | } |
| 1893 | |
| 1894 | // Loop through bound objects and increment their in_use counts. |
| 1895 | void ValidationStateTracker::IncrementBoundObjects(CMD_BUFFER_STATE const *cb_node) { |
| 1896 | for (auto obj : cb_node->object_bindings) { |
| 1897 | auto base_obj = GetStateStructPtrFromObject(obj); |
| 1898 | if (base_obj) { |
| 1899 | base_obj->in_use.fetch_add(1); |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | // Track which resources are in-flight by atomically incrementing their "in_use" count |
| 1905 | void ValidationStateTracker::IncrementResources(CMD_BUFFER_STATE *cb_node) { |
| 1906 | cb_node->submitCount++; |
| 1907 | cb_node->in_use.fetch_add(1); |
| 1908 | |
| 1909 | // First Increment for all "generic" objects bound to cmd buffer, followed by special-case objects below |
| 1910 | IncrementBoundObjects(cb_node); |
| 1911 | // TODO : We should be able to remove the NULL look-up checks from the code below as long as |
| 1912 | // all the corresponding cases are verified to cause CB_INVALID state and the CB_INVALID state |
| 1913 | // should then be flagged prior to calling this function |
| 1914 | for (auto event : cb_node->writeEventsBeforeWait) { |
| 1915 | auto event_state = GetEventState(event); |
| 1916 | if (event_state) event_state->write_in_use++; |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | // Decrement in-use count for objects bound to command buffer |
| 1921 | void ValidationStateTracker::DecrementBoundResources(CMD_BUFFER_STATE const *cb_node) { |
| 1922 | BASE_NODE *base_obj = nullptr; |
| 1923 | for (auto obj : cb_node->object_bindings) { |
| 1924 | base_obj = GetStateStructPtrFromObject(obj); |
| 1925 | if (base_obj) { |
| 1926 | base_obj->in_use.fetch_sub(1); |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1931 | void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1932 | std::unordered_map<VkQueue, uint64_t> otherQueueSeqs; |
| 1933 | |
| 1934 | // Roll this queue forward, one submission at a time. |
| 1935 | while (pQueue->seq < seq) { |
| 1936 | auto &submission = pQueue->submissions.front(); |
| 1937 | |
| 1938 | for (auto &wait : submission.waitSemaphores) { |
| 1939 | auto pSemaphore = GetSemaphoreState(wait.semaphore); |
| 1940 | if (pSemaphore) { |
| 1941 | pSemaphore->in_use.fetch_sub(1); |
| 1942 | } |
| 1943 | auto &lastSeq = otherQueueSeqs[wait.queue]; |
| 1944 | lastSeq = std::max(lastSeq, wait.seq); |
| 1945 | } |
| 1946 | |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 1947 | for (auto &signal : submission.signalSemaphores) { |
| 1948 | auto pSemaphore = GetSemaphoreState(signal.semaphore); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1949 | if (pSemaphore) { |
| 1950 | pSemaphore->in_use.fetch_sub(1); |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 1951 | if (pSemaphore->type == VK_SEMAPHORE_TYPE_TIMELINE_KHR && pSemaphore->payload < signal.payload) { |
| 1952 | pSemaphore->payload = signal.payload; |
| 1953 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | for (auto &semaphore : submission.externalSemaphores) { |
| 1958 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 1959 | if (pSemaphore) { |
| 1960 | pSemaphore->in_use.fetch_sub(1); |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | for (auto cb : submission.cbs) { |
| 1965 | auto cb_node = GetCBState(cb); |
| 1966 | if (!cb_node) { |
| 1967 | continue; |
| 1968 | } |
| 1969 | // First perform decrement on general case bound objects |
| 1970 | DecrementBoundResources(cb_node); |
| 1971 | for (auto event : cb_node->writeEventsBeforeWait) { |
| 1972 | auto eventNode = eventMap.find(event); |
| 1973 | if (eventNode != eventMap.end()) { |
| 1974 | eventNode->second.write_in_use--; |
| 1975 | } |
| 1976 | } |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 1977 | QueryMap localQueryToStateMap; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 1978 | VkQueryPool first_pool = VK_NULL_HANDLE; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 1979 | for (auto &function : cb_node->queryUpdates) { |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 1980 | function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &localQueryToStateMap); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | for (auto queryStatePair : localQueryToStateMap) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1984 | if (queryStatePair.second == QUERYSTATE_ENDED) { |
| 1985 | queryToStateMap[queryStatePair.first] = QUERYSTATE_AVAILABLE; |
| 1986 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1987 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1988 | cb_node->in_use.fetch_sub(1); |
| 1989 | } |
| 1990 | |
| 1991 | auto pFence = GetFenceState(submission.fence); |
| 1992 | if (pFence && pFence->scope == kSyncScopeInternal) { |
| 1993 | pFence->state = FENCE_RETIRED; |
| 1994 | } |
| 1995 | |
| 1996 | pQueue->submissions.pop_front(); |
| 1997 | pQueue->seq++; |
| 1998 | } |
| 1999 | |
| 2000 | // Roll other queues forward to the highest seq we saw a wait for |
| 2001 | for (auto qs : otherQueueSeqs) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2002 | RetireWorkOnQueue(GetQueueState(qs.first), qs.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | // Submit a fence to a queue, delimiting previous fences and previous untracked |
| 2007 | // work by it. |
| 2008 | static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) { |
| 2009 | pFence->state = FENCE_INFLIGHT; |
| 2010 | pFence->signaler.first = pQueue->queue; |
| 2011 | pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount; |
| 2012 | } |
| 2013 | |
| 2014 | void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 2015 | VkFence fence, VkResult result) { |
Mark Lobodzinski | 09379db | 2020-05-07 08:22:01 -0600 | [diff] [blame] | 2016 | if (result != VK_SUCCESS) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2017 | uint64_t early_retire_seq = 0; |
| 2018 | auto pQueue = GetQueueState(queue); |
| 2019 | auto pFence = GetFenceState(fence); |
| 2020 | |
| 2021 | if (pFence) { |
| 2022 | if (pFence->scope == kSyncScopeInternal) { |
| 2023 | // Mark fence in use |
| 2024 | SubmitFence(pQueue, pFence, std::max(1u, submitCount)); |
| 2025 | if (!submitCount) { |
| 2026 | // If no submissions, but just dropping a fence on the end of the queue, |
| 2027 | // record an empty submission with just the fence, so we can determine |
| 2028 | // its completion. |
| 2029 | pQueue->submissions.emplace_back(std::vector<VkCommandBuffer>(), std::vector<SEMAPHORE_WAIT>(), |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2030 | std::vector<SEMAPHORE_SIGNAL>(), std::vector<VkSemaphore>(), fence, 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2031 | } |
| 2032 | } else { |
| 2033 | // Retire work up until this fence early, we will not see the wait that corresponds to this signal |
| 2034 | early_retire_seq = pQueue->seq + pQueue->submissions.size(); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | // Now process each individual submit |
| 2039 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 2040 | std::vector<VkCommandBuffer> cbs; |
| 2041 | const VkSubmitInfo *submit = &pSubmits[submit_idx]; |
Jeremy Gebben | 404e683 | 2020-09-29 14:58:07 -0600 | [diff] [blame] | 2042 | std::vector<SEMAPHORE_WAIT> semaphore_waits; |
| 2043 | std::vector<SEMAPHORE_SIGNAL> semaphore_signals; |
| 2044 | std::vector<VkSemaphore> semaphore_externals; |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2045 | const uint64_t next_seq = pQueue->seq + pQueue->submissions.size() + 1; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2046 | auto *timeline_semaphore_submit = lvl_find_in_chain<VkTimelineSemaphoreSubmitInfoKHR>(submit->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2047 | for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) { |
| 2048 | VkSemaphore semaphore = submit->pWaitSemaphores[i]; |
| 2049 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 2050 | if (pSemaphore) { |
| 2051 | if (pSemaphore->scope == kSyncScopeInternal) { |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 2052 | SEMAPHORE_WAIT wait; |
| 2053 | wait.semaphore = semaphore; |
| 2054 | if (pSemaphore->type == VK_SEMAPHORE_TYPE_BINARY_KHR) { |
| 2055 | if (pSemaphore->signaler.first != VK_NULL_HANDLE) { |
| 2056 | wait.queue = pSemaphore->signaler.first; |
| 2057 | wait.seq = pSemaphore->signaler.second; |
| 2058 | semaphore_waits.push_back(wait); |
| 2059 | pSemaphore->in_use.fetch_add(1); |
| 2060 | } |
| 2061 | pSemaphore->signaler.first = VK_NULL_HANDLE; |
| 2062 | pSemaphore->signaled = false; |
| 2063 | } else if (pSemaphore->payload < timeline_semaphore_submit->pWaitSemaphoreValues[i]) { |
| 2064 | wait.queue = queue; |
| 2065 | wait.seq = next_seq; |
| 2066 | wait.payload = timeline_semaphore_submit->pWaitSemaphoreValues[i]; |
| 2067 | semaphore_waits.push_back(wait); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2068 | pSemaphore->in_use.fetch_add(1); |
| 2069 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2070 | } else { |
| 2071 | semaphore_externals.push_back(semaphore); |
| 2072 | pSemaphore->in_use.fetch_add(1); |
| 2073 | if (pSemaphore->scope == kSyncScopeExternalTemporary) { |
| 2074 | pSemaphore->scope = kSyncScopeInternal; |
| 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) { |
| 2080 | VkSemaphore semaphore = submit->pSignalSemaphores[i]; |
| 2081 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 2082 | if (pSemaphore) { |
| 2083 | if (pSemaphore->scope == kSyncScopeInternal) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2084 | SEMAPHORE_SIGNAL signal; |
| 2085 | signal.semaphore = semaphore; |
| 2086 | signal.seq = next_seq; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2087 | if (pSemaphore->type == VK_SEMAPHORE_TYPE_BINARY_KHR) { |
| 2088 | pSemaphore->signaler.first = queue; |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2089 | pSemaphore->signaler.second = next_seq; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2090 | pSemaphore->signaled = true; |
| 2091 | } else { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2092 | signal.payload = timeline_semaphore_submit->pSignalSemaphoreValues[i]; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2093 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2094 | pSemaphore->in_use.fetch_add(1); |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2095 | semaphore_signals.push_back(signal); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2096 | } else { |
| 2097 | // 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] | 2098 | early_retire_seq = std::max(early_retire_seq, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | } |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2102 | const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext); |
| 2103 | uint32_t perf_pass = perf_submit ? perf_submit->counterPassIndex : 0; |
| 2104 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2105 | for (uint32_t i = 0; i < submit->commandBufferCount; i++) { |
| 2106 | auto cb_node = GetCBState(submit->pCommandBuffers[i]); |
| 2107 | if (cb_node) { |
| 2108 | cbs.push_back(submit->pCommandBuffers[i]); |
| 2109 | for (auto secondaryCmdBuffer : cb_node->linkedCommandBuffers) { |
| 2110 | cbs.push_back(secondaryCmdBuffer->commandBuffer); |
| 2111 | IncrementResources(secondaryCmdBuffer); |
| 2112 | } |
| 2113 | IncrementResources(cb_node); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2114 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2115 | VkQueryPool first_pool = VK_NULL_HANDLE; |
| 2116 | EventToStageMap localEventToStageMap; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2117 | QueryMap localQueryToStateMap; |
| 2118 | for (auto &function : cb_node->queryUpdates) { |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2119 | function(nullptr, /*do_validate*/ false, first_pool, perf_pass, &localQueryToStateMap); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | for (auto queryStatePair : localQueryToStateMap) { |
| 2123 | queryToStateMap[queryStatePair.first] = queryStatePair.second; |
| 2124 | } |
| 2125 | |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2126 | for (auto &function : cb_node->eventUpdates) { |
| 2127 | function(nullptr, /*do_validate*/ false, &localEventToStageMap); |
| 2128 | } |
| 2129 | |
| 2130 | for (auto eventStagePair : localEventToStageMap) { |
| 2131 | eventMap[eventStagePair.first].stageMask = eventStagePair.second; |
| 2132 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2133 | } |
| 2134 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2135 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2136 | pQueue->submissions.emplace_back(cbs, semaphore_waits, semaphore_signals, semaphore_externals, |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 2137 | submit_idx == submitCount - 1 ? fence : (VkFence)VK_NULL_HANDLE, perf_pass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | if (early_retire_seq) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2141 | RetireWorkOnQueue(pQueue, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, |
| 2146 | const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory, |
| 2147 | VkResult result) { |
| 2148 | if (VK_SUCCESS == result) { |
| 2149 | AddMemObjInfo(device, *pMemory, pAllocateInfo); |
| 2150 | } |
| 2151 | return; |
| 2152 | } |
| 2153 | |
| 2154 | void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) { |
| 2155 | if (!mem) return; |
| 2156 | DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem); |
| 2157 | const VulkanTypedHandle obj_struct(mem, kVulkanObjectTypeDeviceMemory); |
| 2158 | |
| 2159 | // Clear mem binding for any bound objects |
| 2160 | for (const auto &obj : mem_info->obj_bindings) { |
| 2161 | BINDABLE *bindable_state = nullptr; |
| 2162 | switch (obj.type) { |
| 2163 | case kVulkanObjectTypeImage: |
| 2164 | bindable_state = GetImageState(obj.Cast<VkImage>()); |
| 2165 | break; |
| 2166 | case kVulkanObjectTypeBuffer: |
| 2167 | bindable_state = GetBufferState(obj.Cast<VkBuffer>()); |
| 2168 | break; |
| 2169 | case kVulkanObjectTypeAccelerationStructureNV: |
| 2170 | bindable_state = GetAccelerationStructureState(obj.Cast<VkAccelerationStructureNV>()); |
| 2171 | break; |
| 2172 | |
| 2173 | default: |
| 2174 | // Should only have acceleration structure, buffer, or image objects bound to memory |
| 2175 | assert(0); |
| 2176 | } |
| 2177 | |
| 2178 | if (bindable_state) { |
Jeff Bolz | 41e2905 | 2020-03-29 22:33:55 -0500 | [diff] [blame] | 2179 | // Remove any sparse bindings bound to the resource that use this memory. |
| 2180 | for (auto it = bindable_state->sparse_bindings.begin(); it != bindable_state->sparse_bindings.end();) { |
| 2181 | auto nextit = it; |
| 2182 | nextit++; |
| 2183 | |
| 2184 | auto &sparse_mem_binding = *it; |
| 2185 | if (sparse_mem_binding.mem_state.get() == mem_info) { |
| 2186 | bindable_state->sparse_bindings.erase(it); |
| 2187 | } |
| 2188 | |
| 2189 | it = nextit; |
| 2190 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2191 | bindable_state->UpdateBoundMemorySet(); |
| 2192 | } |
| 2193 | } |
| 2194 | // Any bound cmd buffers are now invalid |
| 2195 | InvalidateCommandBuffers(mem_info->cb_bindings, obj_struct); |
| 2196 | RemoveAliasingImages(mem_info->bound_images); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2197 | mem_info->destroyed = true; |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 2198 | fake_memory.Free(mem_info->fake_base_address); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2199 | memObjMap.erase(mem); |
| 2200 | } |
| 2201 | |
| 2202 | void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, |
| 2203 | VkFence fence, VkResult result) { |
| 2204 | if (result != VK_SUCCESS) return; |
| 2205 | uint64_t early_retire_seq = 0; |
| 2206 | auto pFence = GetFenceState(fence); |
| 2207 | auto pQueue = GetQueueState(queue); |
| 2208 | |
| 2209 | if (pFence) { |
| 2210 | if (pFence->scope == kSyncScopeInternal) { |
| 2211 | SubmitFence(pQueue, pFence, std::max(1u, bindInfoCount)); |
| 2212 | if (!bindInfoCount) { |
| 2213 | // No work to do, just dropping a fence in the queue by itself. |
| 2214 | pQueue->submissions.emplace_back(std::vector<VkCommandBuffer>(), std::vector<SEMAPHORE_WAIT>(), |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2215 | std::vector<SEMAPHORE_SIGNAL>(), std::vector<VkSemaphore>(), fence, 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2216 | } |
| 2217 | } else { |
| 2218 | // Retire work up until this fence early, we will not see the wait that corresponds to this signal |
| 2219 | early_retire_seq = pQueue->seq + pQueue->submissions.size(); |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | for (uint32_t bindIdx = 0; bindIdx < bindInfoCount; ++bindIdx) { |
| 2224 | const VkBindSparseInfo &bindInfo = pBindInfo[bindIdx]; |
| 2225 | // Track objects tied to memory |
| 2226 | for (uint32_t j = 0; j < bindInfo.bufferBindCount; j++) { |
| 2227 | for (uint32_t k = 0; k < bindInfo.pBufferBinds[j].bindCount; k++) { |
| 2228 | auto sparse_binding = bindInfo.pBufferBinds[j].pBinds[k]; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2229 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2230 | VulkanTypedHandle(bindInfo.pBufferBinds[j].buffer, kVulkanObjectTypeBuffer)); |
| 2231 | } |
| 2232 | } |
| 2233 | for (uint32_t j = 0; j < bindInfo.imageOpaqueBindCount; j++) { |
| 2234 | for (uint32_t k = 0; k < bindInfo.pImageOpaqueBinds[j].bindCount; k++) { |
| 2235 | auto sparse_binding = bindInfo.pImageOpaqueBinds[j].pBinds[k]; |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 2236 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2237 | VulkanTypedHandle(bindInfo.pImageOpaqueBinds[j].image, kVulkanObjectTypeImage)); |
| 2238 | } |
| 2239 | } |
| 2240 | for (uint32_t j = 0; j < bindInfo.imageBindCount; j++) { |
| 2241 | for (uint32_t k = 0; k < bindInfo.pImageBinds[j].bindCount; k++) { |
| 2242 | auto sparse_binding = bindInfo.pImageBinds[j].pBinds[k]; |
| 2243 | // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data |
| 2244 | 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] | 2245 | SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, size, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2246 | VulkanTypedHandle(bindInfo.pImageBinds[j].image, kVulkanObjectTypeImage)); |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | std::vector<SEMAPHORE_WAIT> semaphore_waits; |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2251 | std::vector<SEMAPHORE_SIGNAL> semaphore_signals; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2252 | std::vector<VkSemaphore> semaphore_externals; |
| 2253 | for (uint32_t i = 0; i < bindInfo.waitSemaphoreCount; ++i) { |
| 2254 | VkSemaphore semaphore = bindInfo.pWaitSemaphores[i]; |
| 2255 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 2256 | if (pSemaphore) { |
| 2257 | if (pSemaphore->scope == kSyncScopeInternal) { |
| 2258 | if (pSemaphore->signaler.first != VK_NULL_HANDLE) { |
| 2259 | semaphore_waits.push_back({semaphore, pSemaphore->signaler.first, pSemaphore->signaler.second}); |
| 2260 | pSemaphore->in_use.fetch_add(1); |
| 2261 | } |
| 2262 | pSemaphore->signaler.first = VK_NULL_HANDLE; |
| 2263 | pSemaphore->signaled = false; |
| 2264 | } else { |
| 2265 | semaphore_externals.push_back(semaphore); |
| 2266 | pSemaphore->in_use.fetch_add(1); |
| 2267 | if (pSemaphore->scope == kSyncScopeExternalTemporary) { |
| 2268 | pSemaphore->scope = kSyncScopeInternal; |
| 2269 | } |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | for (uint32_t i = 0; i < bindInfo.signalSemaphoreCount; ++i) { |
| 2274 | VkSemaphore semaphore = bindInfo.pSignalSemaphores[i]; |
| 2275 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 2276 | if (pSemaphore) { |
| 2277 | if (pSemaphore->scope == kSyncScopeInternal) { |
| 2278 | pSemaphore->signaler.first = queue; |
| 2279 | pSemaphore->signaler.second = pQueue->seq + pQueue->submissions.size() + 1; |
| 2280 | pSemaphore->signaled = true; |
| 2281 | pSemaphore->in_use.fetch_add(1); |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2282 | |
| 2283 | SEMAPHORE_SIGNAL signal; |
| 2284 | signal.semaphore = semaphore; |
| 2285 | signal.seq = pSemaphore->signaler.second; |
| 2286 | semaphore_signals.push_back(signal); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2287 | } else { |
| 2288 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
| 2289 | early_retire_seq = std::max(early_retire_seq, pQueue->seq + pQueue->submissions.size() + 1); |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | pQueue->submissions.emplace_back(std::vector<VkCommandBuffer>(), semaphore_waits, semaphore_signals, semaphore_externals, |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2295 | bindIdx == bindInfoCount - 1 ? fence : (VkFence)VK_NULL_HANDLE, 0); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | if (early_retire_seq) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2299 | RetireWorkOnQueue(pQueue, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, |
| 2304 | const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, |
| 2305 | VkResult result) { |
| 2306 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2307 | auto semaphore_state = std::make_shared<SEMAPHORE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2308 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 2309 | semaphore_state->signaler.second = 0; |
| 2310 | semaphore_state->signaled = false; |
| 2311 | semaphore_state->scope = kSyncScopeInternal; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2312 | semaphore_state->type = VK_SEMAPHORE_TYPE_BINARY_KHR; |
| 2313 | semaphore_state->payload = 0; |
| 2314 | auto semaphore_type_create_info = lvl_find_in_chain<VkSemaphoreTypeCreateInfoKHR>(pCreateInfo->pNext); |
| 2315 | if (semaphore_type_create_info) { |
| 2316 | semaphore_state->type = semaphore_type_create_info->semaphoreType; |
| 2317 | semaphore_state->payload = semaphore_type_create_info->initialValue; |
| 2318 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2319 | semaphoreMap[*pSemaphore] = std::move(semaphore_state); |
| 2320 | } |
| 2321 | |
| 2322 | void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBitsKHR handle_type, |
| 2323 | VkSemaphoreImportFlagsKHR flags) { |
| 2324 | SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore); |
| 2325 | if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) { |
| 2326 | if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR) && |
| 2327 | sema_node->scope == kSyncScopeInternal) { |
| 2328 | sema_node->scope = kSyncScopeExternalTemporary; |
| 2329 | } else { |
| 2330 | sema_node->scope = kSyncScopeExternalPermanent; |
| 2331 | } |
| 2332 | } |
| 2333 | } |
| 2334 | |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 2335 | void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfoKHR *pSignalInfo, |
| 2336 | VkResult result) { |
| 2337 | auto *pSemaphore = GetSemaphoreState(pSignalInfo->semaphore); |
| 2338 | pSemaphore->payload = pSignalInfo->value; |
| 2339 | } |
| 2340 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2341 | void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) { |
| 2342 | auto mem_info = GetDevMemState(mem); |
| 2343 | if (mem_info) { |
| 2344 | mem_info->mapped_range.offset = offset; |
| 2345 | mem_info->mapped_range.size = size; |
| 2346 | mem_info->p_driver_data = *ppData; |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | void ValidationStateTracker::RetireFence(VkFence fence) { |
| 2351 | auto pFence = GetFenceState(fence); |
| 2352 | if (pFence && pFence->scope == kSyncScopeInternal) { |
| 2353 | if (pFence->signaler.first != VK_NULL_HANDLE) { |
| 2354 | // Fence signaller is a queue -- use this as proof that prior operations on that queue have completed. |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2355 | RetireWorkOnQueue(GetQueueState(pFence->signaler.first), pFence->signaler.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2356 | } else { |
| 2357 | // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark |
| 2358 | // the fence as retired. |
| 2359 | pFence->state = FENCE_RETIRED; |
| 2360 | } |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 2365 | VkBool32 waitAll, uint64_t timeout, VkResult result) { |
| 2366 | if (VK_SUCCESS != result) return; |
| 2367 | |
| 2368 | // When we know that all fences are complete we can clean/remove their CBs |
| 2369 | if ((VK_TRUE == waitAll) || (1 == fenceCount)) { |
| 2370 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 2371 | RetireFence(pFences[i]); |
| 2372 | } |
| 2373 | } |
| 2374 | // NOTE : Alternate case not handled here is when some fences have completed. In |
| 2375 | // this case for app to guarantee which fences completed it will have to call |
| 2376 | // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete. |
| 2377 | } |
| 2378 | |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2379 | void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) { |
| 2380 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 2381 | if (pSemaphore) { |
| 2382 | for (auto &pair : queueMap) { |
| 2383 | QUEUE_STATE &queueState = pair.second; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2384 | uint64_t max_seq = 0; |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2385 | for (const auto &submission : queueState.submissions) { |
| 2386 | for (const auto &signalSemaphore : submission.signalSemaphores) { |
| 2387 | if (signalSemaphore.semaphore == semaphore && signalSemaphore.payload <= until_payload) { |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2388 | if (signalSemaphore.seq > max_seq) { |
| 2389 | max_seq = signalSemaphore.seq; |
| 2390 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | } |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 2394 | if (max_seq) { |
| 2395 | RetireWorkOnQueue(&queueState, max_seq); |
| 2396 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | } |
| 2400 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 2401 | void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 2402 | VkResult result) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 2403 | if (VK_SUCCESS != result) return; |
| 2404 | |
| 2405 | for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) { |
| 2406 | RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]); |
| 2407 | } |
| 2408 | } |
| 2409 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 2410 | void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 2411 | VkResult result) { |
| 2412 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 2413 | } |
| 2414 | |
| 2415 | void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, |
| 2416 | uint64_t timeout, VkResult result) { |
| 2417 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 2418 | } |
| 2419 | |
Adrian Coca Lorente | c7d7610 | 2020-09-28 13:58:16 +0200 | [diff] [blame] | 2420 | void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2421 | VkResult result) { |
| 2422 | if (VK_SUCCESS != result) return; |
| 2423 | |
| 2424 | RetireTimelineSemaphore(semaphore, *pValue); |
| 2425 | } |
| 2426 | |
| 2427 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2428 | VkResult result) { |
| 2429 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 2430 | } |
| 2431 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 2432 | VkResult result) { |
| 2433 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 2434 | } |
| 2435 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2436 | void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) { |
| 2437 | if (VK_SUCCESS != result) return; |
| 2438 | RetireFence(fence); |
| 2439 | } |
| 2440 | |
| 2441 | void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) { |
| 2442 | // Add queue to tracking set only if it is new |
| 2443 | auto queue_is_new = queues.emplace(queue); |
| 2444 | if (queue_is_new.second == true) { |
| 2445 | QUEUE_STATE *queue_state = &queueMap[queue]; |
| 2446 | queue_state->queue = queue; |
| 2447 | queue_state->queueFamilyIndex = queue_family_index; |
| 2448 | queue_state->seq = 0; |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, |
| 2453 | VkQueue *pQueue) { |
| 2454 | RecordGetDeviceQueueState(queueFamilyIndex, *pQueue); |
| 2455 | } |
| 2456 | |
| 2457 | void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) { |
| 2458 | RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue); |
| 2459 | } |
| 2460 | |
| 2461 | void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 2462 | if (VK_SUCCESS != result) return; |
| 2463 | QUEUE_STATE *queue_state = GetQueueState(queue); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2464 | RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 2468 | if (VK_SUCCESS != result) return; |
| 2469 | for (auto &queue : queueMap) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 2470 | RetireWorkOnQueue(&queue.second, queue.second.seq + queue.second.submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) { |
| 2475 | if (!fence) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2476 | auto fence_state = GetFenceState(fence); |
| 2477 | fence_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2478 | fenceMap.erase(fence); |
| 2479 | } |
| 2480 | |
| 2481 | void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore, |
| 2482 | const VkAllocationCallbacks *pAllocator) { |
| 2483 | if (!semaphore) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2484 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 2485 | semaphore_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2486 | semaphoreMap.erase(semaphore); |
| 2487 | } |
| 2488 | |
| 2489 | void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 2490 | if (!event) return; |
| 2491 | EVENT_STATE *event_state = GetEventState(event); |
| 2492 | const VulkanTypedHandle obj_struct(event, kVulkanObjectTypeEvent); |
| 2493 | InvalidateCommandBuffers(event_state->cb_bindings, obj_struct); |
| 2494 | eventMap.erase(event); |
| 2495 | } |
| 2496 | |
| 2497 | void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool, |
| 2498 | const VkAllocationCallbacks *pAllocator) { |
| 2499 | if (!queryPool) return; |
| 2500 | QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool); |
| 2501 | const VulkanTypedHandle obj_struct(queryPool, kVulkanObjectTypeQueryPool); |
| 2502 | InvalidateCommandBuffers(qp_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2503 | qp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2504 | queryPoolMap.erase(queryPool); |
| 2505 | } |
| 2506 | |
| 2507 | // Object with given handle is being bound to memory w/ given mem_info struct. |
| 2508 | // Track the newly bound memory range with given memoryOffset |
| 2509 | // Also scan any previous ranges, track aliased ranges with new range, and flag an error if a linear |
| 2510 | // and non-linear range incorrectly overlap. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2511 | void ValidationStateTracker::InsertMemoryRange(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info, |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2512 | VkDeviceSize memoryOffset) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2513 | if (typed_handle.type == kVulkanObjectTypeImage) { |
| 2514 | mem_info->bound_images.insert(typed_handle.Cast<VkImage>()); |
| 2515 | } else if (typed_handle.type == kVulkanObjectTypeBuffer) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2516 | mem_info->bound_buffers.insert(typed_handle.Cast<VkBuffer>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2517 | } else if (typed_handle.type == kVulkanObjectTypeAccelerationStructureNV) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2518 | mem_info->bound_acceleration_structures.insert(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2519 | } else { |
| 2520 | // Unsupported object type |
| 2521 | assert(false); |
| 2522 | } |
| 2523 | } |
| 2524 | |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2525 | void ValidationStateTracker::InsertImageMemoryRange(VkImage image, DEVICE_MEMORY_STATE *mem_info, VkDeviceSize mem_offset) { |
| 2526 | InsertMemoryRange(VulkanTypedHandle(image, kVulkanObjectTypeImage), mem_info, mem_offset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2527 | } |
| 2528 | |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2529 | void ValidationStateTracker::InsertBufferMemoryRange(VkBuffer buffer, DEVICE_MEMORY_STATE *mem_info, VkDeviceSize mem_offset) { |
| 2530 | InsertMemoryRange(VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer), mem_info, mem_offset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | void ValidationStateTracker::InsertAccelerationStructureMemoryRange(VkAccelerationStructureNV as, DEVICE_MEMORY_STATE *mem_info, |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2534 | VkDeviceSize mem_offset) { |
| 2535 | InsertMemoryRange(VulkanTypedHandle(as, kVulkanObjectTypeAccelerationStructureNV), mem_info, mem_offset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | // This function will remove the handle-to-index mapping from the appropriate map. |
| 2539 | static void RemoveMemoryRange(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) { |
| 2540 | if (typed_handle.type == kVulkanObjectTypeImage) { |
| 2541 | mem_info->bound_images.erase(typed_handle.Cast<VkImage>()); |
| 2542 | } else if (typed_handle.type == kVulkanObjectTypeBuffer) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2543 | mem_info->bound_buffers.erase(typed_handle.Cast<VkBuffer>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2544 | } else if (typed_handle.type == kVulkanObjectTypeAccelerationStructureNV) { |
locke-lunarg | 37c410a | 2020-02-17 17:34:13 -0700 | [diff] [blame] | 2545 | mem_info->bound_acceleration_structures.erase(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2546 | } else { |
| 2547 | // Unsupported object type |
| 2548 | assert(false); |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | void ValidationStateTracker::RemoveBufferMemoryRange(VkBuffer buffer, DEVICE_MEMORY_STATE *mem_info) { |
| 2553 | RemoveMemoryRange(VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer), mem_info); |
| 2554 | } |
| 2555 | |
| 2556 | void ValidationStateTracker::RemoveImageMemoryRange(VkImage image, DEVICE_MEMORY_STATE *mem_info) { |
| 2557 | RemoveMemoryRange(VulkanTypedHandle(image, kVulkanObjectTypeImage), mem_info); |
| 2558 | } |
| 2559 | |
| 2560 | void ValidationStateTracker::RemoveAccelerationStructureMemoryRange(VkAccelerationStructureNV as, DEVICE_MEMORY_STATE *mem_info) { |
| 2561 | RemoveMemoryRange(VulkanTypedHandle(as, kVulkanObjectTypeAccelerationStructureNV), mem_info); |
| 2562 | } |
| 2563 | |
| 2564 | void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) { |
| 2565 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2566 | if (buffer_state) { |
| 2567 | // Track bound memory range information |
| 2568 | auto mem_info = GetDevMemState(mem); |
| 2569 | if (mem_info) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2570 | InsertBufferMemoryRange(buffer, mem_info, memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2571 | } |
| 2572 | // Track objects tied to memory |
| 2573 | SetMemBinding(mem, buffer_state, memoryOffset, VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer)); |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, |
| 2578 | VkDeviceSize memoryOffset, VkResult result) { |
| 2579 | if (VK_SUCCESS != result) return; |
| 2580 | UpdateBindBufferMemoryState(buffer, mem, memoryOffset); |
| 2581 | } |
| 2582 | |
| 2583 | void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
| 2584 | const VkBindBufferMemoryInfoKHR *pBindInfos, VkResult result) { |
| 2585 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2586 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
| 2591 | const VkBindBufferMemoryInfoKHR *pBindInfos, VkResult result) { |
| 2592 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2593 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2594 | } |
| 2595 | } |
| 2596 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2597 | void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2598 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2599 | if (buffer_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2600 | buffer_state->memory_requirements_checked = true; |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, |
| 2605 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2606 | RecordGetBufferMemoryRequirementsState(buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device, |
| 2610 | const VkBufferMemoryRequirementsInfo2KHR *pInfo, |
| 2611 | VkMemoryRequirements2KHR *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2612 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device, |
| 2616 | const VkBufferMemoryRequirementsInfo2KHR *pInfo, |
| 2617 | VkMemoryRequirements2KHR *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2618 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2619 | } |
| 2620 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2621 | void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2622 | const VkImagePlaneMemoryRequirementsInfo *plane_info = |
| 2623 | (pInfo == nullptr) ? nullptr : lvl_find_in_chain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2624 | IMAGE_STATE *image_state = GetImageState(image); |
| 2625 | if (image_state) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2626 | if (plane_info != nullptr) { |
| 2627 | // Multi-plane image |
| 2628 | image_state->memory_requirements_checked = false; // Each image plane needs to be checked itself |
| 2629 | if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) { |
| 2630 | image_state->plane0_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2631 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) { |
| 2632 | image_state->plane1_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2633 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) { |
| 2634 | image_state->plane2_memory_requirements_checked = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2635 | } |
| 2636 | } else { |
| 2637 | // Single Plane image |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2638 | image_state->memory_requirements_checked = true; |
| 2639 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image, |
| 2644 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2645 | RecordGetImageMemoryRequirementsState(image, nullptr); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2649 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2650 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device, |
| 2654 | const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2655 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2656 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | static void RecordGetImageSparseMemoryRequirementsState(IMAGE_STATE *image_state, |
| 2660 | VkSparseImageMemoryRequirements *sparse_image_memory_requirements) { |
| 2661 | image_state->sparse_requirements.emplace_back(*sparse_image_memory_requirements); |
| 2662 | if (sparse_image_memory_requirements->formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2663 | image_state->sparse_metadata_required = true; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements( |
| 2668 | VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount, |
| 2669 | VkSparseImageMemoryRequirements *pSparseMemoryRequirements) { |
| 2670 | auto image_state = GetImageState(image); |
| 2671 | image_state->get_sparse_reqs_called = true; |
| 2672 | if (!pSparseMemoryRequirements) return; |
| 2673 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2674 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i]); |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2( |
| 2679 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2680 | VkSparseImageMemoryRequirements2KHR *pSparseMemoryRequirements) { |
| 2681 | auto image_state = GetImageState(pInfo->image); |
| 2682 | image_state->get_sparse_reqs_called = true; |
| 2683 | if (!pSparseMemoryRequirements) return; |
| 2684 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2685 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2686 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2687 | } |
| 2688 | } |
| 2689 | |
| 2690 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR( |
| 2691 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2692 | VkSparseImageMemoryRequirements2KHR *pSparseMemoryRequirements) { |
| 2693 | auto image_state = GetImageState(pInfo->image); |
| 2694 | image_state->get_sparse_reqs_called = true; |
| 2695 | if (!pSparseMemoryRequirements) return; |
| 2696 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2697 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2698 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, |
| 2703 | const VkAllocationCallbacks *pAllocator) { |
| 2704 | if (!shaderModule) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2705 | auto shader_module_state = GetShaderModuleState(shaderModule); |
| 2706 | shader_module_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2707 | shaderModuleMap.erase(shaderModule); |
| 2708 | } |
| 2709 | |
| 2710 | void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, |
| 2711 | const VkAllocationCallbacks *pAllocator) { |
| 2712 | if (!pipeline) return; |
| 2713 | PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline); |
| 2714 | const VulkanTypedHandle obj_struct(pipeline, kVulkanObjectTypePipeline); |
| 2715 | // Any bound cmd buffers are now invalid |
| 2716 | InvalidateCommandBuffers(pipeline_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2717 | pipeline_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2718 | pipelineMap.erase(pipeline); |
| 2719 | } |
| 2720 | |
| 2721 | void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, |
| 2722 | const VkAllocationCallbacks *pAllocator) { |
| 2723 | if (!pipelineLayout) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2724 | auto pipeline_layout_state = GetPipelineLayout(pipelineLayout); |
| 2725 | pipeline_layout_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2726 | pipelineLayoutMap.erase(pipelineLayout); |
| 2727 | } |
| 2728 | |
| 2729 | void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler, |
| 2730 | const VkAllocationCallbacks *pAllocator) { |
| 2731 | if (!sampler) return; |
| 2732 | SAMPLER_STATE *sampler_state = GetSamplerState(sampler); |
| 2733 | const VulkanTypedHandle obj_struct(sampler, kVulkanObjectTypeSampler); |
| 2734 | // Any bound cmd buffers are now invalid |
| 2735 | if (sampler_state) { |
| 2736 | InvalidateCommandBuffers(sampler_state->cb_bindings, obj_struct); |
Yuly Novikov | 424cdd5 | 2020-05-26 16:45:12 -0400 | [diff] [blame] | 2737 | |
| 2738 | if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 2739 | sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
| 2740 | custom_border_color_sampler_count--; |
| 2741 | } |
| 2742 | |
| 2743 | sampler_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2744 | } |
| 2745 | samplerMap.erase(sampler); |
| 2746 | } |
| 2747 | |
| 2748 | void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, |
| 2749 | const VkAllocationCallbacks *pAllocator) { |
| 2750 | if (!descriptorSetLayout) return; |
| 2751 | auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout); |
| 2752 | if (layout_it != descriptorSetLayoutMap.end()) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 2753 | layout_it->second.get()->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2754 | descriptorSetLayoutMap.erase(layout_it); |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 2759 | const VkAllocationCallbacks *pAllocator) { |
| 2760 | if (!descriptorPool) return; |
| 2761 | DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool); |
| 2762 | const VulkanTypedHandle obj_struct(descriptorPool, kVulkanObjectTypeDescriptorPool); |
| 2763 | if (desc_pool_state) { |
| 2764 | // Any bound cmd buffers are now invalid |
| 2765 | InvalidateCommandBuffers(desc_pool_state->cb_bindings, obj_struct); |
| 2766 | // Free sets that were in this pool |
| 2767 | for (auto ds : desc_pool_state->sets) { |
| 2768 | FreeDescriptorSet(ds); |
| 2769 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2770 | desc_pool_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2771 | descriptorPoolMap.erase(descriptorPool); |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | // Free all command buffers in given list, removing all references/links to them using ResetCommandBufferState |
| 2776 | void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count, |
| 2777 | const VkCommandBuffer *command_buffers) { |
| 2778 | for (uint32_t i = 0; i < command_buffer_count; i++) { |
John Zulauf | d1f85d4 | 2020-04-15 12:23:15 -0600 | [diff] [blame] | 2779 | // Allow any derived class to clean up command buffer state |
| 2780 | if (command_buffer_free_callback) { |
| 2781 | (*command_buffer_free_callback)(command_buffers[i]); |
| 2782 | } |
| 2783 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2784 | auto cb_state = GetCBState(command_buffers[i]); |
| 2785 | // Remove references to command buffer's state and delete |
| 2786 | if (cb_state) { |
| 2787 | // reset prior to delete, removing various references to it. |
| 2788 | // TODO: fix this, it's insane. |
| 2789 | ResetCommandBufferState(cb_state->commandBuffer); |
| 2790 | // Remove the cb_state's references from COMMAND_POOL_STATEs |
| 2791 | pool_state->commandBuffers.erase(command_buffers[i]); |
| 2792 | // Remove the cb debug labels |
| 2793 | EraseCmdDebugUtilsLabel(report_data, cb_state->commandBuffer); |
| 2794 | // Remove CBState from CB map |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2795 | cb_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2796 | commandBufferMap.erase(cb_state->commandBuffer); |
| 2797 | } |
| 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, |
| 2802 | uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) { |
| 2803 | auto pPool = GetCommandPoolState(commandPool); |
| 2804 | FreeCommandBufferStates(pPool, commandBufferCount, pCommandBuffers); |
| 2805 | } |
| 2806 | |
| 2807 | void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, |
| 2808 | const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool, |
| 2809 | VkResult result) { |
| 2810 | if (VK_SUCCESS != result) return; |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 2811 | VkCommandPool command_pool = *pCommandPool; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2812 | auto cmd_pool_state = std::make_shared<COMMAND_POOL_STATE>(); |
sfricke-samsung | c154337 | 2020-08-18 22:37:27 -0700 | [diff] [blame] | 2813 | cmd_pool_state->commandPool = command_pool; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2814 | cmd_pool_state->createFlags = pCreateInfo->flags; |
| 2815 | cmd_pool_state->queueFamilyIndex = pCreateInfo->queueFamilyIndex; |
sfricke-samsung | 0c45edc | 2020-07-01 22:19:53 -0700 | [diff] [blame] | 2816 | 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] | 2817 | commandPoolMap[command_pool] = std::move(cmd_pool_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo, |
| 2821 | const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool, |
| 2822 | VkResult result) { |
| 2823 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2824 | auto query_pool_state = std::make_shared<QUERY_POOL_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2825 | query_pool_state->createInfo = *pCreateInfo; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2826 | query_pool_state->pool = *pQueryPool; |
| 2827 | if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
| 2828 | const auto *perf = lvl_find_in_chain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext); |
| 2829 | const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex]; |
| 2830 | |
| 2831 | for (uint32_t i = 0; i < perf->counterIndexCount; i++) { |
| 2832 | const auto &counter = counters.counters[perf->pCounterIndices[i]]; |
| 2833 | switch (counter.scope) { |
| 2834 | case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR: |
| 2835 | query_pool_state->has_perf_scope_command_buffer = true; |
| 2836 | break; |
| 2837 | case VK_QUERY_SCOPE_RENDER_PASS_KHR: |
| 2838 | query_pool_state->has_perf_scope_render_pass = true; |
| 2839 | break; |
| 2840 | default: |
| 2841 | break; |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->phys_device, perf, |
| 2846 | &query_pool_state->n_performance_passes); |
| 2847 | } |
| 2848 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2849 | queryPoolMap[*pQueryPool] = std::move(query_pool_state); |
| 2850 | |
| 2851 | QueryObject query_obj{*pQueryPool, 0u}; |
| 2852 | for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) { |
| 2853 | query_obj.query = i; |
| 2854 | queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN; |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, |
| 2859 | const VkAllocationCallbacks *pAllocator) { |
| 2860 | if (!commandPool) return; |
| 2861 | COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool); |
| 2862 | // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers |
| 2863 | // "When a pool is destroyed, all command buffers allocated from the pool are freed." |
| 2864 | if (cp_state) { |
| 2865 | // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration. |
| 2866 | std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()}; |
| 2867 | 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] | 2868 | cp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2869 | commandPoolMap.erase(commandPool); |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, |
| 2874 | VkCommandPoolResetFlags flags, VkResult result) { |
| 2875 | if (VK_SUCCESS != result) return; |
| 2876 | // Reset all of the CBs allocated from this pool |
| 2877 | auto command_pool_state = GetCommandPoolState(commandPool); |
| 2878 | for (auto cmdBuffer : command_pool_state->commandBuffers) { |
| 2879 | ResetCommandBufferState(cmdBuffer); |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 2884 | VkResult result) { |
| 2885 | for (uint32_t i = 0; i < fenceCount; ++i) { |
| 2886 | auto pFence = GetFenceState(pFences[i]); |
| 2887 | if (pFence) { |
| 2888 | if (pFence->scope == kSyncScopeInternal) { |
| 2889 | pFence->state = FENCE_UNSIGNALED; |
| 2890 | } else if (pFence->scope == kSyncScopeExternalTemporary) { |
| 2891 | pFence->scope = kSyncScopeInternal; |
| 2892 | } |
| 2893 | } |
| 2894 | } |
| 2895 | } |
| 2896 | |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 2897 | // For given cb_nodes, invalidate them and track object causing invalidation. |
| 2898 | // InvalidateCommandBuffers and InvalidateLinkedCommandBuffers are essentially |
| 2899 | // the same, except one takes a map and one takes a set, and InvalidateCommandBuffers |
| 2900 | // can also unlink objects from command buffers. |
| 2901 | void ValidationStateTracker::InvalidateCommandBuffers(small_unordered_map<CMD_BUFFER_STATE *, int, 8> &cb_nodes, |
| 2902 | const VulkanTypedHandle &obj, bool unlink) { |
| 2903 | for (const auto &cb_node_pair : cb_nodes) { |
| 2904 | auto &cb_node = cb_node_pair.first; |
| 2905 | if (cb_node->state == CB_RECORDING) { |
| 2906 | cb_node->state = CB_INVALID_INCOMPLETE; |
| 2907 | } else if (cb_node->state == CB_RECORDED) { |
| 2908 | cb_node->state = CB_INVALID_COMPLETE; |
| 2909 | } |
| 2910 | cb_node->broken_bindings.push_back(obj); |
| 2911 | |
| 2912 | // if secondary, then propagate the invalidation to the primaries that will call us. |
| 2913 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
| 2914 | InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj); |
| 2915 | } |
| 2916 | if (unlink) { |
| 2917 | int index = cb_node_pair.second; |
| 2918 | assert(cb_node->object_bindings[index] == obj); |
| 2919 | cb_node->object_bindings[index] = VulkanTypedHandle(); |
| 2920 | } |
| 2921 | } |
| 2922 | if (unlink) { |
| 2923 | cb_nodes.clear(); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | void ValidationStateTracker::InvalidateLinkedCommandBuffers(std::unordered_set<CMD_BUFFER_STATE *> &cb_nodes, |
| 2928 | const VulkanTypedHandle &obj) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2929 | for (auto cb_node : cb_nodes) { |
| 2930 | if (cb_node->state == CB_RECORDING) { |
| 2931 | cb_node->state = CB_INVALID_INCOMPLETE; |
| 2932 | } else if (cb_node->state == CB_RECORDED) { |
| 2933 | cb_node->state = CB_INVALID_COMPLETE; |
| 2934 | } |
| 2935 | cb_node->broken_bindings.push_back(obj); |
| 2936 | |
| 2937 | // if secondary, then propagate the invalidation to the primaries that will call us. |
| 2938 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 2939 | InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, |
| 2945 | const VkAllocationCallbacks *pAllocator) { |
| 2946 | if (!framebuffer) return; |
| 2947 | FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer); |
| 2948 | const VulkanTypedHandle obj_struct(framebuffer, kVulkanObjectTypeFramebuffer); |
| 2949 | InvalidateCommandBuffers(framebuffer_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2950 | framebuffer_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2951 | frameBufferMap.erase(framebuffer); |
| 2952 | } |
| 2953 | |
| 2954 | void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, |
| 2955 | const VkAllocationCallbacks *pAllocator) { |
| 2956 | if (!renderPass) return; |
| 2957 | RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass); |
| 2958 | const VulkanTypedHandle obj_struct(renderPass, kVulkanObjectTypeRenderPass); |
| 2959 | InvalidateCommandBuffers(rp_state->cb_bindings, obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2960 | rp_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2961 | renderPassMap.erase(renderPass); |
| 2962 | } |
| 2963 | |
| 2964 | void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, |
| 2965 | const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) { |
| 2966 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2967 | auto fence_state = std::make_shared<FENCE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2968 | fence_state->fence = *pFence; |
| 2969 | fence_state->createInfo = *pCreateInfo; |
| 2970 | fence_state->state = (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) ? FENCE_RETIRED : FENCE_UNSIGNALED; |
| 2971 | fenceMap[*pFence] = std::move(fence_state); |
| 2972 | } |
| 2973 | |
| 2974 | bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 2975 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 2976 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2977 | void *cgpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2978 | // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use. |
| 2979 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 2980 | cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 2981 | cgpl_state->pipe_state.reserve(count); |
| 2982 | for (uint32_t i = 0; i < count; i++) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2983 | cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 2984 | (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] | 2985 | (cgpl_state->pipe_state)[i]->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2986 | } |
| 2987 | return false; |
| 2988 | } |
| 2989 | |
| 2990 | void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 2991 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 2992 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 2993 | VkResult result, void *cgpl_state_data) { |
| 2994 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 2995 | // This API may create pipelines regardless of the return value |
| 2996 | for (uint32_t i = 0; i < count; i++) { |
| 2997 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 2998 | (cgpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 2999 | pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]); |
| 3000 | } |
| 3001 | } |
| 3002 | cgpl_state->pipe_state.clear(); |
| 3003 | } |
| 3004 | |
| 3005 | bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3006 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 3007 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3008 | void *ccpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3009 | auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 3010 | ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 3011 | ccpl_state->pipe_state.reserve(count); |
| 3012 | for (uint32_t i = 0; i < count; i++) { |
| 3013 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3014 | ccpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3015 | ccpl_state->pipe_state.back()->initComputePipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3016 | ccpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3017 | } |
| 3018 | return false; |
| 3019 | } |
| 3020 | |
| 3021 | void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 3022 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 3023 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 3024 | VkResult result, void *ccpl_state_data) { |
| 3025 | create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 3026 | |
| 3027 | // This API may create pipelines regardless of the return value |
| 3028 | for (uint32_t i = 0; i < count; i++) { |
| 3029 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3030 | (ccpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3031 | pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]); |
| 3032 | } |
| 3033 | } |
| 3034 | ccpl_state->pipe_state.clear(); |
| 3035 | } |
| 3036 | |
| 3037 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, |
| 3038 | uint32_t count, |
| 3039 | const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 3040 | const VkAllocationCallbacks *pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3041 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3042 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 3043 | crtpl_state->pipe_state.reserve(count); |
| 3044 | for (uint32_t i = 0; i < count; i++) { |
| 3045 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3046 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3047 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3048 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3049 | } |
| 3050 | return false; |
| 3051 | } |
| 3052 | |
| 3053 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV( |
| 3054 | VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 3055 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) { |
| 3056 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 3057 | // This API may create pipelines regardless of the return value |
| 3058 | for (uint32_t i = 0; i < count; i++) { |
| 3059 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3060 | (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3061 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 3062 | } |
| 3063 | } |
| 3064 | crtpl_state->pipe_state.clear(); |
| 3065 | } |
| 3066 | |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 3067 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkPipelineCache pipelineCache, |
| 3068 | uint32_t count, |
| 3069 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 3070 | const VkAllocationCallbacks *pAllocator, |
| 3071 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
| 3072 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 3073 | crtpl_state->pipe_state.reserve(count); |
| 3074 | for (uint32_t i = 0; i < count; i++) { |
| 3075 | // Create and initialize internal tracking data structure |
| 3076 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
| 3077 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
| 3078 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
| 3079 | } |
| 3080 | return false; |
| 3081 | } |
| 3082 | |
| 3083 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR( |
| 3084 | VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 3085 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) { |
| 3086 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 3087 | // This API may create pipelines regardless of the return value |
| 3088 | for (uint32_t i = 0; i < count; i++) { |
| 3089 | if (pPipelines[i] != VK_NULL_HANDLE) { |
| 3090 | (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i]; |
| 3091 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 3092 | } |
| 3093 | } |
| 3094 | crtpl_state->pipe_state.clear(); |
| 3095 | } |
| 3096 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3097 | void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, |
| 3098 | const VkAllocationCallbacks *pAllocator, VkSampler *pSampler, |
| 3099 | VkResult result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3100 | samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo); |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 3101 | if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) |
| 3102 | custom_border_color_sampler_count++; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device, |
| 3106 | const VkDescriptorSetLayoutCreateInfo *pCreateInfo, |
| 3107 | const VkAllocationCallbacks *pAllocator, |
| 3108 | VkDescriptorSetLayout *pSetLayout, VkResult result) { |
| 3109 | if (VK_SUCCESS != result) return; |
| 3110 | descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout); |
| 3111 | } |
| 3112 | |
| 3113 | // For repeatable sorting, not very useful for "memory in range" search |
| 3114 | struct PushConstantRangeCompare { |
| 3115 | bool operator()(const VkPushConstantRange *lhs, const VkPushConstantRange *rhs) const { |
| 3116 | if (lhs->offset == rhs->offset) { |
| 3117 | if (lhs->size == rhs->size) { |
| 3118 | // The comparison is arbitrary, but avoids false aliasing by comparing all fields. |
| 3119 | return lhs->stageFlags < rhs->stageFlags; |
| 3120 | } |
| 3121 | // If the offsets are the same then sorting by the end of range is useful for validation |
| 3122 | return lhs->size < rhs->size; |
| 3123 | } |
| 3124 | return lhs->offset < rhs->offset; |
| 3125 | } |
| 3126 | }; |
| 3127 | |
| 3128 | static PushConstantRangesDict push_constant_ranges_dict; |
| 3129 | |
| 3130 | PushConstantRangesId GetCanonicalId(const VkPipelineLayoutCreateInfo *info) { |
| 3131 | if (!info->pPushConstantRanges) { |
| 3132 | // Hand back the empty entry (creating as needed)... |
| 3133 | return push_constant_ranges_dict.look_up(PushConstantRanges()); |
| 3134 | } |
| 3135 | |
| 3136 | // Sort the input ranges to ensure equivalent ranges map to the same id |
| 3137 | std::set<const VkPushConstantRange *, PushConstantRangeCompare> sorted; |
| 3138 | for (uint32_t i = 0; i < info->pushConstantRangeCount; i++) { |
| 3139 | sorted.insert(info->pPushConstantRanges + i); |
| 3140 | } |
| 3141 | |
Jeremy Hayes | f34b9fb | 2019-12-06 09:37:03 -0700 | [diff] [blame] | 3142 | PushConstantRanges ranges; |
| 3143 | ranges.reserve(sorted.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3144 | for (const auto range : sorted) { |
| 3145 | ranges.emplace_back(*range); |
| 3146 | } |
| 3147 | return push_constant_ranges_dict.look_up(std::move(ranges)); |
| 3148 | } |
| 3149 | |
| 3150 | // Dictionary of canoncial form of the pipeline set layout of descriptor set layouts |
| 3151 | static PipelineLayoutSetLayoutsDict pipeline_layout_set_layouts_dict; |
| 3152 | |
| 3153 | // Dictionary of canonical form of the "compatible for set" records |
| 3154 | static PipelineLayoutCompatDict pipeline_layout_compat_dict; |
| 3155 | |
| 3156 | static PipelineLayoutCompatId GetCanonicalId(const uint32_t set_index, const PushConstantRangesId pcr_id, |
| 3157 | const PipelineLayoutSetLayoutsId set_layouts_id) { |
| 3158 | return pipeline_layout_compat_dict.look_up(PipelineLayoutCompatDef(set_index, pcr_id, set_layouts_id)); |
| 3159 | } |
| 3160 | |
| 3161 | void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, |
| 3162 | const VkAllocationCallbacks *pAllocator, |
| 3163 | VkPipelineLayout *pPipelineLayout, VkResult result) { |
| 3164 | if (VK_SUCCESS != result) return; |
| 3165 | |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3166 | auto pipeline_layout_state = std::make_shared<PIPELINE_LAYOUT_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3167 | pipeline_layout_state->layout = *pPipelineLayout; |
| 3168 | pipeline_layout_state->set_layouts.resize(pCreateInfo->setLayoutCount); |
| 3169 | PipelineLayoutSetLayoutsDef set_layouts(pCreateInfo->setLayoutCount); |
| 3170 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3171 | pipeline_layout_state->set_layouts[i] = GetDescriptorSetLayoutShared(pCreateInfo->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3172 | set_layouts[i] = pipeline_layout_state->set_layouts[i]->GetLayoutId(); |
| 3173 | } |
| 3174 | |
| 3175 | // Get canonical form IDs for the "compatible for set" contents |
| 3176 | pipeline_layout_state->push_constant_ranges = GetCanonicalId(pCreateInfo); |
| 3177 | auto set_layouts_id = pipeline_layout_set_layouts_dict.look_up(set_layouts); |
| 3178 | pipeline_layout_state->compat_for_set.reserve(pCreateInfo->setLayoutCount); |
| 3179 | |
| 3180 | // Create table of "compatible for set N" cannonical forms for trivial accept validation |
| 3181 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
| 3182 | pipeline_layout_state->compat_for_set.emplace_back( |
| 3183 | GetCanonicalId(i, pipeline_layout_state->push_constant_ranges, set_layouts_id)); |
| 3184 | } |
| 3185 | pipelineLayoutMap[*pPipelineLayout] = std::move(pipeline_layout_state); |
| 3186 | } |
| 3187 | |
| 3188 | void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, |
| 3189 | const VkAllocationCallbacks *pAllocator, |
| 3190 | VkDescriptorPool *pDescriptorPool, VkResult result) { |
| 3191 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3192 | descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 3196 | VkDescriptorPoolResetFlags flags, VkResult result) { |
| 3197 | if (VK_SUCCESS != result) return; |
| 3198 | DESCRIPTOR_POOL_STATE *pPool = GetDescriptorPoolState(descriptorPool); |
| 3199 | // TODO: validate flags |
| 3200 | // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet |
| 3201 | for (auto ds : pPool->sets) { |
| 3202 | FreeDescriptorSet(ds); |
| 3203 | } |
| 3204 | pPool->sets.clear(); |
| 3205 | // Reset available count for each type and available sets for this pool |
| 3206 | for (auto it = pPool->availableDescriptorTypeCount.begin(); it != pPool->availableDescriptorTypeCount.end(); ++it) { |
| 3207 | pPool->availableDescriptorTypeCount[it->first] = pPool->maxDescriptorTypeCount[it->first]; |
| 3208 | } |
| 3209 | pPool->availableSets = pPool->maxSets; |
| 3210 | } |
| 3211 | |
| 3212 | bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device, |
| 3213 | const VkDescriptorSetAllocateInfo *pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 3214 | VkDescriptorSet *pDescriptorSets, void *ads_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3215 | // Always update common data |
| 3216 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 3217 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 3218 | UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state); |
| 3219 | |
| 3220 | return false; |
| 3221 | } |
| 3222 | |
| 3223 | // Allocation state was good and call down chain was made so update state based on allocating descriptor sets |
| 3224 | void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 3225 | VkDescriptorSet *pDescriptorSets, VkResult result, |
| 3226 | void *ads_state_data) { |
| 3227 | if (VK_SUCCESS != result) return; |
| 3228 | // All the updates are contained in a single cvdescriptorset function |
| 3229 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 3230 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 3231 | PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state); |
| 3232 | } |
| 3233 | |
| 3234 | void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, |
| 3235 | const VkDescriptorSet *pDescriptorSets) { |
| 3236 | DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool); |
| 3237 | // Update available descriptor sets in pool |
| 3238 | pool_state->availableSets += count; |
| 3239 | |
| 3240 | // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap |
| 3241 | for (uint32_t i = 0; i < count; ++i) { |
| 3242 | if (pDescriptorSets[i] != VK_NULL_HANDLE) { |
| 3243 | auto descriptor_set = setMap[pDescriptorSets[i]].get(); |
| 3244 | uint32_t type_index = 0, descriptor_count = 0; |
| 3245 | for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) { |
| 3246 | type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j)); |
| 3247 | descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j); |
| 3248 | pool_state->availableDescriptorTypeCount[type_index] += descriptor_count; |
| 3249 | } |
| 3250 | FreeDescriptorSet(descriptor_set); |
| 3251 | pool_state->sets.erase(descriptor_set); |
| 3252 | } |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, |
| 3257 | const VkWriteDescriptorSet *pDescriptorWrites, |
| 3258 | uint32_t descriptorCopyCount, |
| 3259 | const VkCopyDescriptorSet *pDescriptorCopies) { |
| 3260 | cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, |
| 3261 | pDescriptorCopies); |
| 3262 | } |
| 3263 | |
| 3264 | void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, |
| 3265 | VkCommandBuffer *pCommandBuffer, VkResult result) { |
| 3266 | if (VK_SUCCESS != result) return; |
Jeff Bolz | 6835fda | 2019-10-06 00:15:34 -0500 | [diff] [blame] | 3267 | auto pPool = GetCommandPoolShared(pCreateInfo->commandPool); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3268 | if (pPool) { |
| 3269 | for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) { |
| 3270 | // Add command buffer to its commandPool map |
| 3271 | pPool->commandBuffers.insert(pCommandBuffer[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3272 | auto pCB = std::make_shared<CMD_BUFFER_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3273 | pCB->createInfo = *pCreateInfo; |
Jeff Bolz | 6835fda | 2019-10-06 00:15:34 -0500 | [diff] [blame] | 3274 | pCB->command_pool = pPool; |
sfricke-samsung | 0c45edc | 2020-07-01 22:19:53 -0700 | [diff] [blame] | 3275 | pCB->unprotected = pPool->unprotected; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3276 | // Add command buffer to map |
| 3277 | commandBufferMap[pCommandBuffer[i]] = std::move(pCB); |
| 3278 | ResetCommandBufferState(pCommandBuffer[i]); |
| 3279 | } |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | // Add bindings between the given cmd buffer & framebuffer and the framebuffer's children |
| 3284 | void ValidationStateTracker::AddFramebufferBinding(CMD_BUFFER_STATE *cb_state, FRAMEBUFFER_STATE *fb_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3285 | AddCommandBufferBinding(fb_state->cb_bindings, VulkanTypedHandle(fb_state->framebuffer, kVulkanObjectTypeFramebuffer, fb_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3286 | cb_state); |
Mark Lobodzinski | 544b3dd | 2019-12-03 14:44:54 -0700 | [diff] [blame] | 3287 | // If imageless fb, skip fb binding |
| 3288 | if (fb_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3289 | const uint32_t attachmentCount = fb_state->createInfo.attachmentCount; |
| 3290 | for (uint32_t attachment = 0; attachment < attachmentCount; ++attachment) { |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 3291 | auto view_state = GetAttachmentImageViewState(cb_state, fb_state, attachment); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3292 | if (view_state) { |
| 3293 | AddCommandBufferBindingImageView(cb_state, view_state); |
| 3294 | } |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 3299 | const VkCommandBufferBeginInfo *pBeginInfo) { |
| 3300 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3301 | if (!cb_state) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3302 | if (cb_state->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) { |
| 3303 | // Secondary Command Buffer |
| 3304 | const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo; |
| 3305 | if (pInfo) { |
| 3306 | if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) { |
| 3307 | assert(pInfo->renderPass); |
| 3308 | auto framebuffer = GetFramebufferState(pInfo->framebuffer); |
| 3309 | if (framebuffer) { |
| 3310 | // Connect this framebuffer and its children to this cmdBuffer |
| 3311 | AddFramebufferBinding(cb_state, framebuffer); |
| 3312 | } |
| 3313 | } |
| 3314 | } |
| 3315 | } |
| 3316 | if (CB_RECORDED == cb_state->state || CB_INVALID_COMPLETE == cb_state->state) { |
| 3317 | ResetCommandBufferState(commandBuffer); |
| 3318 | } |
| 3319 | // Set updated state here in case implicit reset occurs above |
| 3320 | cb_state->state = CB_RECORDING; |
| 3321 | cb_state->beginInfo = *pBeginInfo; |
| 3322 | if (cb_state->beginInfo.pInheritanceInfo) { |
| 3323 | cb_state->inheritanceInfo = *(cb_state->beginInfo.pInheritanceInfo); |
| 3324 | cb_state->beginInfo.pInheritanceInfo = &cb_state->inheritanceInfo; |
| 3325 | // If we are a secondary command-buffer and inheriting. Update the items we should inherit. |
| 3326 | if ((cb_state->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) && |
| 3327 | (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3328 | cb_state->activeRenderPass = GetShared<RENDER_PASS_STATE>(cb_state->beginInfo.pInheritanceInfo->renderPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3329 | cb_state->activeSubpass = cb_state->beginInfo.pInheritanceInfo->subpass; |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 3330 | if (cb_state->beginInfo.pInheritanceInfo->framebuffer) { |
| 3331 | cb_state->activeFramebuffer = GetShared<FRAMEBUFFER_STATE>(cb_state->beginInfo.pInheritanceInfo->framebuffer); |
| 3332 | if (cb_state->activeFramebuffer) cb_state->framebuffers.insert(cb_state->activeFramebuffer); |
| 3333 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | auto chained_device_group_struct = lvl_find_in_chain<VkDeviceGroupCommandBufferBeginInfo>(pBeginInfo->pNext); |
| 3338 | if (chained_device_group_struct) { |
| 3339 | cb_state->initial_device_mask = chained_device_group_struct->deviceMask; |
| 3340 | } else { |
| 3341 | cb_state->initial_device_mask = (1 << physical_device_count) - 1; |
| 3342 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3343 | |
| 3344 | cb_state->performance_lock_acquired = performance_lock_acquired; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) { |
| 3348 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3349 | if (!cb_state) return; |
| 3350 | // Cached validation is specific to a specific recording of a specific command buffer. |
| 3351 | for (auto descriptor_set : cb_state->validated_descriptor_sets) { |
| 3352 | descriptor_set->ClearCachedValidation(cb_state); |
| 3353 | } |
| 3354 | cb_state->validated_descriptor_sets.clear(); |
| 3355 | if (VK_SUCCESS == result) { |
| 3356 | cb_state->state = CB_RECORDED; |
| 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags, |
| 3361 | VkResult result) { |
| 3362 | if (VK_SUCCESS == result) { |
| 3363 | ResetCommandBufferState(commandBuffer); |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) { |
| 3368 | // initially assume everything is static state |
| 3369 | CBStatusFlags flags = CBSTATUS_ALL_STATE_SET; |
| 3370 | |
| 3371 | if (ds) { |
| 3372 | for (uint32_t i = 0; i < ds->dynamicStateCount; i++) { |
| 3373 | switch (ds->pDynamicStates[i]) { |
| 3374 | case VK_DYNAMIC_STATE_LINE_WIDTH: |
| 3375 | flags &= ~CBSTATUS_LINE_WIDTH_SET; |
| 3376 | break; |
| 3377 | case VK_DYNAMIC_STATE_DEPTH_BIAS: |
| 3378 | flags &= ~CBSTATUS_DEPTH_BIAS_SET; |
| 3379 | break; |
| 3380 | case VK_DYNAMIC_STATE_BLEND_CONSTANTS: |
| 3381 | flags &= ~CBSTATUS_BLEND_CONSTANTS_SET; |
| 3382 | break; |
| 3383 | case VK_DYNAMIC_STATE_DEPTH_BOUNDS: |
| 3384 | flags &= ~CBSTATUS_DEPTH_BOUNDS_SET; |
| 3385 | break; |
| 3386 | case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK: |
| 3387 | flags &= ~CBSTATUS_STENCIL_READ_MASK_SET; |
| 3388 | break; |
| 3389 | case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK: |
| 3390 | flags &= ~CBSTATUS_STENCIL_WRITE_MASK_SET; |
| 3391 | break; |
| 3392 | case VK_DYNAMIC_STATE_STENCIL_REFERENCE: |
| 3393 | flags &= ~CBSTATUS_STENCIL_REFERENCE_SET; |
| 3394 | break; |
| 3395 | case VK_DYNAMIC_STATE_SCISSOR: |
| 3396 | flags &= ~CBSTATUS_SCISSOR_SET; |
| 3397 | break; |
| 3398 | case VK_DYNAMIC_STATE_VIEWPORT: |
| 3399 | flags &= ~CBSTATUS_VIEWPORT_SET; |
| 3400 | break; |
| 3401 | case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV: |
| 3402 | flags &= ~CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
| 3403 | break; |
| 3404 | case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV: |
| 3405 | flags &= ~CBSTATUS_SHADING_RATE_PALETTE_SET; |
| 3406 | break; |
| 3407 | case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT: |
| 3408 | flags &= ~CBSTATUS_LINE_STIPPLE_SET; |
| 3409 | break; |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 3410 | case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV: |
| 3411 | flags &= ~CBSTATUS_VIEWPORT_W_SCALING_SET; |
| 3412 | break; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3413 | case VK_DYNAMIC_STATE_CULL_MODE_EXT: |
| 3414 | flags &= ~CBSTATUS_CULL_MODE_SET; |
| 3415 | break; |
| 3416 | case VK_DYNAMIC_STATE_FRONT_FACE_EXT: |
| 3417 | flags &= ~CBSTATUS_FRONT_FACE_SET; |
| 3418 | break; |
| 3419 | case VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT: |
| 3420 | flags &= ~CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 3421 | break; |
| 3422 | case VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT: |
| 3423 | flags &= ~CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 3424 | break; |
| 3425 | case VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT: |
| 3426 | flags &= ~CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 3427 | break; |
| 3428 | case VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT: |
| 3429 | flags &= ~CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 3430 | break; |
| 3431 | case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT: |
| 3432 | flags &= ~CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 3433 | break; |
| 3434 | case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT: |
| 3435 | flags &= ~CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 3436 | break; |
| 3437 | case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT: |
| 3438 | flags &= ~CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 3439 | break; |
| 3440 | case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT: |
| 3441 | flags &= ~CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 3442 | break; |
| 3443 | case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT: |
| 3444 | flags &= ~CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 3445 | break; |
| 3446 | case VK_DYNAMIC_STATE_STENCIL_OP_EXT: |
| 3447 | flags &= ~CBSTATUS_STENCIL_OP_SET; |
| 3448 | break; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3449 | default: |
| 3450 | break; |
| 3451 | } |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | return flags; |
| 3456 | } |
| 3457 | |
| 3458 | // Validation cache: |
| 3459 | // CV is the bottommost implementor of this extension. Don't pass calls down. |
| 3460 | // utility function to set collective state for pipeline |
| 3461 | void SetPipelineState(PIPELINE_STATE *pPipe) { |
| 3462 | // If any attachment used by this pipeline has blendEnable, set top-level blendEnable |
| 3463 | if (pPipe->graphicsPipelineCI.pColorBlendState) { |
| 3464 | for (size_t i = 0; i < pPipe->attachments.size(); ++i) { |
| 3465 | if (VK_TRUE == pPipe->attachments[i].blendEnable) { |
| 3466 | if (((pPipe->attachments[i].dstAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3467 | (pPipe->attachments[i].dstAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3468 | ((pPipe->attachments[i].dstColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3469 | (pPipe->attachments[i].dstColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3470 | ((pPipe->attachments[i].srcAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3471 | (pPipe->attachments[i].srcAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 3472 | ((pPipe->attachments[i].srcColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 3473 | (pPipe->attachments[i].srcColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA))) { |
| 3474 | pPipe->blendConstantsEnabled = true; |
| 3475 | } |
| 3476 | } |
| 3477 | } |
| 3478 | } |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 3479 | // Check if sample location is enabled |
| 3480 | if (pPipe->graphicsPipelineCI.pMultisampleState) { |
| 3481 | const VkPipelineSampleLocationsStateCreateInfoEXT *sample_location_state = |
| 3482 | lvl_find_in_chain<VkPipelineSampleLocationsStateCreateInfoEXT>(pPipe->graphicsPipelineCI.pMultisampleState->pNext); |
| 3483 | if (sample_location_state != nullptr) { |
| 3484 | pPipe->sample_location_enabled = sample_location_state->sampleLocationsEnable; |
| 3485 | } |
| 3486 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 3490 | VkPipeline pipeline) { |
| 3491 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3492 | assert(cb_state); |
| 3493 | |
| 3494 | auto pipe_state = GetPipelineState(pipeline); |
| 3495 | if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) { |
| 3496 | cb_state->status &= ~cb_state->static_status; |
| 3497 | cb_state->static_status = MakeStaticStateMask(pipe_state->graphicsPipelineCI.ptr()->pDynamicState); |
| 3498 | cb_state->status |= cb_state->static_status; |
| 3499 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3500 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, pipe_state->pipeline_layout->layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3501 | cb_state->lastBound[pipelineBindPoint].pipeline_state = pipe_state; |
| 3502 | SetPipelineState(pipe_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3503 | AddCommandBufferBinding(pipe_state->cb_bindings, VulkanTypedHandle(pipeline, kVulkanObjectTypePipeline), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3507 | uint32_t viewportCount, const VkViewport *pViewports) { |
| 3508 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3509 | cb_state->viewportMask |= ((1u << viewportCount) - 1u) << firstViewport; |
| 3510 | cb_state->status |= CBSTATUS_VIEWPORT_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3511 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor, |
| 3515 | uint32_t exclusiveScissorCount, |
| 3516 | const VkRect2D *pExclusiveScissors) { |
| 3517 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3518 | // TODO: We don't have VUIDs for validating that all exclusive scissors have been set. |
| 3519 | // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor; |
| 3520 | cb_state->status |= CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3521 | cb_state->static_status &= ~CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView, |
| 3525 | VkImageLayout imageLayout) { |
| 3526 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3527 | |
| 3528 | if (imageView != VK_NULL_HANDLE) { |
| 3529 | auto view_state = GetImageViewState(imageView); |
| 3530 | AddCommandBufferBindingImageView(cb_state, view_state); |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3535 | uint32_t viewportCount, |
| 3536 | const VkShadingRatePaletteNV *pShadingRatePalettes) { |
| 3537 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3538 | // TODO: We don't have VUIDs for validating that all shading rate palettes have been set. |
| 3539 | // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport; |
| 3540 | cb_state->status |= CBSTATUS_SHADING_RATE_PALETTE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3541 | cb_state->static_status &= ~CBSTATUS_SHADING_RATE_PALETTE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device, |
| 3545 | const VkAccelerationStructureCreateInfoNV *pCreateInfo, |
| 3546 | const VkAllocationCallbacks *pAllocator, |
| 3547 | VkAccelerationStructureNV *pAccelerationStructure, |
| 3548 | VkResult result) { |
| 3549 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3550 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3551 | |
| 3552 | // Query the requirements in case the application doesn't (to avoid bind/validation time query) |
| 3553 | VkAccelerationStructureMemoryRequirementsInfoNV as_memory_requirements_info = {}; |
| 3554 | as_memory_requirements_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 3555 | as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV; |
| 3556 | as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure; |
| 3557 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements); |
| 3558 | |
| 3559 | VkAccelerationStructureMemoryRequirementsInfoNV scratch_memory_req_info = {}; |
| 3560 | scratch_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 3561 | scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV; |
| 3562 | scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3563 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info, |
| 3564 | &as_state->build_scratch_memory_requirements); |
| 3565 | |
| 3566 | VkAccelerationStructureMemoryRequirementsInfoNV update_memory_req_info = {}; |
| 3567 | update_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV; |
| 3568 | update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV; |
| 3569 | update_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3570 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info, |
| 3571 | &as_state->update_scratch_memory_requirements); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 3572 | as_state->allocator = pAllocator; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3573 | accelerationStructureMap[*pAccelerationStructure] = std::move(as_state); |
| 3574 | } |
| 3575 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3576 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device, |
| 3577 | const VkAccelerationStructureCreateInfoKHR *pCreateInfo, |
| 3578 | const VkAllocationCallbacks *pAllocator, |
| 3579 | VkAccelerationStructureKHR *pAccelerationStructure, |
| 3580 | VkResult result) { |
| 3581 | if (VK_SUCCESS != result) return; |
| 3582 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo); |
| 3583 | |
| 3584 | // Query the requirements in case the application doesn't (to avoid bind/validation time query) |
| 3585 | VkAccelerationStructureMemoryRequirementsInfoKHR as_memory_requirements_info = {}; |
| 3586 | as_memory_requirements_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_KHR; |
| 3587 | as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_KHR; |
| 3588 | as_memory_requirements_info.buildType = VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR; |
| 3589 | as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure; |
| 3590 | DispatchGetAccelerationStructureMemoryRequirementsKHR(device, &as_memory_requirements_info, &as_state->memory_requirements); |
| 3591 | |
| 3592 | VkAccelerationStructureMemoryRequirementsInfoKHR scratch_memory_req_info = {}; |
| 3593 | scratch_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_KHR; |
| 3594 | scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_KHR; |
| 3595 | scratch_memory_req_info.buildType = VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR; |
| 3596 | scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3597 | DispatchGetAccelerationStructureMemoryRequirementsKHR(device, &scratch_memory_req_info, |
| 3598 | &as_state->build_scratch_memory_requirements); |
| 3599 | |
| 3600 | VkAccelerationStructureMemoryRequirementsInfoKHR update_memory_req_info = {}; |
| 3601 | update_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_KHR; |
| 3602 | update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_KHR; |
| 3603 | update_memory_req_info.buildType = VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR; |
| 3604 | update_memory_req_info.accelerationStructure = as_state->acceleration_structure; |
| 3605 | DispatchGetAccelerationStructureMemoryRequirementsKHR(device, &update_memory_req_info, |
| 3606 | &as_state->update_scratch_memory_requirements); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 3607 | as_state->allocator = pAllocator; |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3608 | accelerationStructureMap[*pAccelerationStructure] = std::move(as_state); |
| 3609 | } |
| 3610 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3611 | void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV( |
| 3612 | VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2KHR *pMemoryRequirements) { |
| 3613 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureState(pInfo->accelerationStructure); |
| 3614 | if (as_state != nullptr) { |
| 3615 | if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) { |
| 3616 | as_state->memory_requirements = *pMemoryRequirements; |
| 3617 | as_state->memory_requirements_checked = true; |
| 3618 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) { |
| 3619 | as_state->build_scratch_memory_requirements = *pMemoryRequirements; |
| 3620 | as_state->build_scratch_memory_requirements_checked = true; |
| 3621 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) { |
| 3622 | as_state->update_scratch_memory_requirements = *pMemoryRequirements; |
| 3623 | as_state->update_scratch_memory_requirements_checked = true; |
| 3624 | } |
| 3625 | } |
| 3626 | } |
| 3627 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3628 | void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryCommon( |
| 3629 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoKHR *pBindInfos, VkResult result, |
| 3630 | bool isNV) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3631 | if (VK_SUCCESS != result) return; |
| 3632 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3633 | const VkBindAccelerationStructureMemoryInfoKHR &info = pBindInfos[i]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3634 | |
| 3635 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureState(info.accelerationStructure); |
| 3636 | if (as_state) { |
| 3637 | // Track bound memory range information |
| 3638 | auto mem_info = GetDevMemState(info.memory); |
| 3639 | if (mem_info) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 3640 | InsertAccelerationStructureMemoryRange(info.accelerationStructure, mem_info, info.memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3641 | } |
| 3642 | // Track objects tied to memory |
| 3643 | SetMemBinding(info.memory, as_state, info.memoryOffset, |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3644 | VulkanTypedHandle(info.accelerationStructure, kVulkanObjectTypeAccelerationStructureKHR)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3645 | |
| 3646 | // GPU validation of top level acceleration structure building needs acceleration structure handles. |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3647 | // XXX TODO: Query device address for KHR extension |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 3648 | if (enabled[gpu_validation] && isNV) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3649 | DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle); |
| 3650 | } |
| 3651 | } |
| 3652 | } |
| 3653 | } |
| 3654 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3655 | void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV( |
| 3656 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) { |
| 3657 | PostCallRecordBindAccelerationStructureMemoryCommon(device, bindInfoCount, pBindInfos, result, true); |
| 3658 | } |
| 3659 | |
| 3660 | void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryKHR( |
| 3661 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoKHR *pBindInfos, VkResult result) { |
| 3662 | PostCallRecordBindAccelerationStructureMemoryCommon(device, bindInfoCount, pBindInfos, result, false); |
| 3663 | } |
| 3664 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3665 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV( |
| 3666 | VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset, |
| 3667 | VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) { |
| 3668 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3669 | if (cb_state == nullptr) { |
| 3670 | return; |
| 3671 | } |
| 3672 | |
| 3673 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureState(dst); |
| 3674 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureState(src); |
| 3675 | if (dst_as_state != nullptr) { |
| 3676 | dst_as_state->built = true; |
| 3677 | dst_as_state->build_info.initialize(pInfo); |
| 3678 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3679 | } |
| 3680 | if (src_as_state != nullptr) { |
| 3681 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3682 | } |
| 3683 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 3684 | } |
| 3685 | |
| 3686 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer, |
| 3687 | VkAccelerationStructureNV dst, |
| 3688 | VkAccelerationStructureNV src, |
| 3689 | VkCopyAccelerationStructureModeNV mode) { |
| 3690 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3691 | if (cb_state) { |
| 3692 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureState(src); |
| 3693 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureState(dst); |
| 3694 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 3695 | dst_as_state->built = true; |
| 3696 | dst_as_state->build_info = src_as_state->build_info; |
| 3697 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 3698 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 3699 | } |
| 3700 | } |
| 3701 | } |
| 3702 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3703 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device, |
| 3704 | VkAccelerationStructureKHR accelerationStructure, |
| 3705 | const VkAllocationCallbacks *pAllocator) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3706 | if (!accelerationStructure) return; |
| 3707 | auto *as_state = GetAccelerationStructureState(accelerationStructure); |
| 3708 | if (as_state) { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3709 | const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureKHR); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3710 | InvalidateCommandBuffers(as_state->cb_bindings, obj_struct); |
| 3711 | for (auto mem_binding : as_state->GetBoundMemory()) { |
locke-lunarg | cf04d58 | 2019-11-26 00:31:50 -0700 | [diff] [blame] | 3712 | RemoveAccelerationStructureMemoryRange(accelerationStructure, mem_binding); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3713 | } |
| 3714 | ClearMemoryObjectBindings(obj_struct); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3715 | as_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3716 | accelerationStructureMap.erase(accelerationStructure); |
| 3717 | } |
| 3718 | } |
| 3719 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3720 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device, |
| 3721 | VkAccelerationStructureNV accelerationStructure, |
| 3722 | const VkAllocationCallbacks *pAllocator) { |
| 3723 | PreCallRecordDestroyAccelerationStructureKHR(device, accelerationStructure, pAllocator); |
| 3724 | } |
| 3725 | |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 3726 | void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3727 | uint32_t viewportCount, |
| 3728 | const VkViewportWScalingNV *pViewportWScalings) { |
| 3729 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3730 | cb_state->status |= CBSTATUS_VIEWPORT_W_SCALING_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3731 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_W_SCALING_SET; |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 3732 | } |
| 3733 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3734 | void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) { |
| 3735 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3736 | cb_state->status |= CBSTATUS_LINE_WIDTH_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3737 | cb_state->static_status &= ~CBSTATUS_LINE_WIDTH_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor, |
| 3741 | uint16_t lineStipplePattern) { |
| 3742 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3743 | cb_state->status |= CBSTATUS_LINE_STIPPLE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3744 | cb_state->static_status &= ~CBSTATUS_LINE_STIPPLE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, |
| 3748 | float depthBiasClamp, float depthBiasSlopeFactor) { |
| 3749 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3750 | cb_state->status |= CBSTATUS_DEPTH_BIAS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3751 | cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3752 | } |
| 3753 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3754 | void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, |
| 3755 | const VkRect2D *pScissors) { |
| 3756 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3757 | cb_state->scissorMask |= ((1u << scissorCount) - 1u) << firstScissor; |
| 3758 | cb_state->status |= CBSTATUS_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3759 | cb_state->static_status &= ~CBSTATUS_SCISSOR_SET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3760 | } |
| 3761 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3762 | void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) { |
| 3763 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3764 | cb_state->status |= CBSTATUS_BLEND_CONSTANTS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3765 | cb_state->static_status &= ~CBSTATUS_BLEND_CONSTANTS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds, |
| 3769 | float maxDepthBounds) { |
| 3770 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3771 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3772 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 3776 | uint32_t compareMask) { |
| 3777 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3778 | cb_state->status |= CBSTATUS_STENCIL_READ_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3779 | cb_state->static_status &= ~CBSTATUS_STENCIL_READ_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 3783 | uint32_t writeMask) { |
| 3784 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3785 | cb_state->status |= CBSTATUS_STENCIL_WRITE_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3786 | cb_state->static_status &= ~CBSTATUS_STENCIL_WRITE_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 3790 | uint32_t reference) { |
| 3791 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3792 | cb_state->status |= CBSTATUS_STENCIL_REFERENCE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3793 | cb_state->static_status &= ~CBSTATUS_STENCIL_REFERENCE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | // Update pipeline_layout bind points applying the "Pipeline Layout Compatibility" rules. |
| 3797 | // One of pDescriptorSets or push_descriptor_set should be nullptr, indicating whether this |
| 3798 | // is called for CmdBindDescriptorSets or CmdPushDescriptorSet. |
| 3799 | void ValidationStateTracker::UpdateLastBoundDescriptorSets(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipeline_bind_point, |
| 3800 | const PIPELINE_LAYOUT_STATE *pipeline_layout, uint32_t first_set, |
| 3801 | uint32_t set_count, const VkDescriptorSet *pDescriptorSets, |
| 3802 | cvdescriptorset::DescriptorSet *push_descriptor_set, |
| 3803 | uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets) { |
| 3804 | assert((pDescriptorSets == nullptr) ^ (push_descriptor_set == nullptr)); |
| 3805 | // Defensive |
| 3806 | assert(pipeline_layout); |
| 3807 | if (!pipeline_layout) return; |
| 3808 | |
| 3809 | uint32_t required_size = first_set + set_count; |
| 3810 | const uint32_t last_binding_index = required_size - 1; |
| 3811 | assert(last_binding_index < pipeline_layout->compat_for_set.size()); |
| 3812 | |
| 3813 | // Some useful shorthand |
| 3814 | auto &last_bound = cb_state->lastBound[pipeline_bind_point]; |
| 3815 | auto &pipe_compat_ids = pipeline_layout->compat_for_set; |
| 3816 | const uint32_t current_size = static_cast<uint32_t>(last_bound.per_set.size()); |
| 3817 | |
| 3818 | // We need this three times in this function, but nowhere else |
| 3819 | auto push_descriptor_cleanup = [&last_bound](const cvdescriptorset::DescriptorSet *ds) -> bool { |
| 3820 | if (ds && ds->IsPushDescriptor()) { |
| 3821 | assert(ds == last_bound.push_descriptor_set.get()); |
| 3822 | last_bound.push_descriptor_set = nullptr; |
| 3823 | return true; |
| 3824 | } |
| 3825 | return false; |
| 3826 | }; |
| 3827 | |
| 3828 | // Clean up the "disturbed" before and after the range to be set |
| 3829 | if (required_size < current_size) { |
| 3830 | if (last_bound.per_set[last_binding_index].compat_id_for_set != pipe_compat_ids[last_binding_index]) { |
| 3831 | // We're disturbing those after last, we'll shrink below, but first need to check for and cleanup the push_descriptor |
| 3832 | for (auto set_idx = required_size; set_idx < current_size; ++set_idx) { |
| 3833 | if (push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set)) break; |
| 3834 | } |
| 3835 | } else { |
| 3836 | // We're not disturbing past last, so leave the upper binding data alone. |
| 3837 | required_size = current_size; |
| 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | // We resize if we need more set entries or if those past "last" are disturbed |
| 3842 | if (required_size != current_size) { |
| 3843 | last_bound.per_set.resize(required_size); |
| 3844 | } |
| 3845 | |
| 3846 | // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update |
| 3847 | for (uint32_t set_idx = 0; set_idx < first_set; ++set_idx) { |
| 3848 | if (last_bound.per_set[set_idx].compat_id_for_set != pipe_compat_ids[set_idx]) { |
| 3849 | push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set); |
| 3850 | last_bound.per_set[set_idx].bound_descriptor_set = nullptr; |
| 3851 | last_bound.per_set[set_idx].dynamicOffsets.clear(); |
| 3852 | last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; |
| 3853 | } |
| 3854 | } |
| 3855 | |
| 3856 | // Now update the bound sets with the input sets |
| 3857 | const uint32_t *input_dynamic_offsets = p_dynamic_offsets; // "read" pointer for dynamic offset data |
| 3858 | for (uint32_t input_idx = 0; input_idx < set_count; input_idx++) { |
| 3859 | auto set_idx = input_idx + first_set; // set_idx is index within layout, input_idx is index within input descriptor sets |
| 3860 | cvdescriptorset::DescriptorSet *descriptor_set = |
| 3861 | push_descriptor_set ? push_descriptor_set : GetSetNode(pDescriptorSets[input_idx]); |
| 3862 | |
| 3863 | // Record binding (or push) |
| 3864 | if (descriptor_set != last_bound.push_descriptor_set.get()) { |
| 3865 | // Only cleanup the push descriptors if they aren't the currently used set. |
| 3866 | push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set); |
| 3867 | } |
| 3868 | last_bound.per_set[set_idx].bound_descriptor_set = descriptor_set; |
| 3869 | last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; // compat ids are canonical *per* set index |
| 3870 | |
| 3871 | if (descriptor_set) { |
| 3872 | auto set_dynamic_descriptor_count = descriptor_set->GetDynamicDescriptorCount(); |
| 3873 | // TODO: Add logic for tracking push_descriptor offsets (here or in caller) |
| 3874 | if (set_dynamic_descriptor_count && input_dynamic_offsets) { |
| 3875 | const uint32_t *end_offset = input_dynamic_offsets + set_dynamic_descriptor_count; |
| 3876 | last_bound.per_set[set_idx].dynamicOffsets = std::vector<uint32_t>(input_dynamic_offsets, end_offset); |
| 3877 | input_dynamic_offsets = end_offset; |
| 3878 | assert(input_dynamic_offsets <= (p_dynamic_offsets + dynamic_offset_count)); |
| 3879 | } else { |
| 3880 | last_bound.per_set[set_idx].dynamicOffsets.clear(); |
| 3881 | } |
| 3882 | if (!descriptor_set->IsPushDescriptor()) { |
| 3883 | // Can't cache validation of push_descriptors |
| 3884 | cb_state->validated_descriptor_sets.insert(descriptor_set); |
| 3885 | } |
| 3886 | } |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | // Update the bound state for the bind point, including the effects of incompatible pipeline layouts |
| 3891 | void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer, |
| 3892 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 3893 | uint32_t firstSet, uint32_t setCount, |
| 3894 | const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount, |
| 3895 | const uint32_t *pDynamicOffsets) { |
| 3896 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3897 | auto pipeline_layout = GetPipelineLayout(layout); |
| 3898 | |
| 3899 | // Resize binding arrays |
| 3900 | uint32_t last_set_index = firstSet + setCount - 1; |
| 3901 | if (last_set_index >= cb_state->lastBound[pipelineBindPoint].per_set.size()) { |
| 3902 | cb_state->lastBound[pipelineBindPoint].per_set.resize(last_set_index + 1); |
| 3903 | } |
| 3904 | |
| 3905 | UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr, |
| 3906 | dynamicOffsetCount, pDynamicOffsets); |
| 3907 | cb_state->lastBound[pipelineBindPoint].pipeline_layout = layout; |
| 3908 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout); |
| 3909 | } |
| 3910 | |
| 3911 | void ValidationStateTracker::RecordCmdPushDescriptorSetState(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipelineBindPoint, |
| 3912 | VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, |
| 3913 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 3914 | const auto &pipeline_layout = GetPipelineLayout(layout); |
| 3915 | // Short circuit invalid updates |
| 3916 | if (!pipeline_layout || (set >= pipeline_layout->set_layouts.size()) || !pipeline_layout->set_layouts[set] || |
| 3917 | !pipeline_layout->set_layouts[set]->IsPushDescriptor()) |
| 3918 | return; |
| 3919 | |
| 3920 | // We need a descriptor set to update the bindings with, compatible with the passed layout |
| 3921 | const auto dsl = pipeline_layout->set_layouts[set]; |
| 3922 | auto &last_bound = cb_state->lastBound[pipelineBindPoint]; |
| 3923 | auto &push_descriptor_set = last_bound.push_descriptor_set; |
| 3924 | // If we are disturbing the current push_desriptor_set clear it |
| 3925 | 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] | 3926 | last_bound.UnbindAndResetPushDescriptorSet(new cvdescriptorset::DescriptorSet(0, nullptr, dsl, 0, this)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, set, 1, nullptr, push_descriptor_set.get(), 0, |
| 3930 | nullptr); |
| 3931 | last_bound.pipeline_layout = layout; |
| 3932 | |
| 3933 | // 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] | 3934 | push_descriptor_set->PerformPushDescriptorsUpdate(this, descriptorWriteCount, pDescriptorWrites); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, |
| 3938 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 3939 | uint32_t set, uint32_t descriptorWriteCount, |
| 3940 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 3941 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3942 | RecordCmdPushDescriptorSetState(cb_state, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites); |
| 3943 | } |
| 3944 | |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 3945 | void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout, |
| 3946 | VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, |
| 3947 | const void *pValues) { |
| 3948 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3949 | if (cb_state != nullptr) { |
| 3950 | ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout); |
| 3951 | |
| 3952 | auto &push_constant_data = cb_state->push_constant_data; |
| 3953 | assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size())); |
| 3954 | std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size)); |
| 3955 | } |
| 3956 | } |
| 3957 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3958 | void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3959 | VkIndexType indexType) { |
| 3960 | auto buffer_state = GetBufferState(buffer); |
| 3961 | auto cb_state = GetCBState(commandBuffer); |
| 3962 | |
| 3963 | cb_state->status |= CBSTATUS_INDEX_BUFFER_BOUND; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3964 | cb_state->static_status &= ~CBSTATUS_INDEX_BUFFER_BOUND; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3965 | cb_state->index_buffer_binding.buffer = buffer; |
| 3966 | cb_state->index_buffer_binding.size = buffer_state->createInfo.size; |
| 3967 | cb_state->index_buffer_binding.offset = offset; |
| 3968 | cb_state->index_buffer_binding.index_type = indexType; |
| 3969 | // Add binding for this index buffer to this commandbuffer |
| 3970 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 3971 | } |
| 3972 | |
| 3973 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 3974 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 3975 | const VkDeviceSize *pOffsets) { |
| 3976 | auto cb_state = GetCBState(commandBuffer); |
| 3977 | |
| 3978 | uint32_t end = firstBinding + bindingCount; |
| 3979 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 3980 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 3981 | } |
| 3982 | |
| 3983 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 3984 | auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding]; |
| 3985 | vertex_buffer_binding.buffer = pBuffers[i]; |
| 3986 | vertex_buffer_binding.offset = pOffsets[i]; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3987 | vertex_buffer_binding.size = VK_WHOLE_SIZE; |
| 3988 | vertex_buffer_binding.stride = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3989 | // Add binding for this vertex buffer to this commandbuffer |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3990 | if (pBuffers[i]) { |
| 3991 | AddCommandBufferBindingBuffer(cb_state, GetBufferState(pBuffers[i])); |
| 3992 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, |
| 3997 | VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) { |
| 3998 | auto cb_state = GetCBState(commandBuffer); |
| 3999 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 4000 | |
| 4001 | // Update bindings between buffer and cmd buffer |
| 4002 | AddCommandBufferBindingBuffer(cb_state, dst_buffer_state); |
| 4003 | } |
| 4004 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4005 | bool ValidationStateTracker::SetEventStageMask(VkEvent event, VkPipelineStageFlags stageMask, |
| 4006 | EventToStageMap *localEventToStageMap) { |
| 4007 | (*localEventToStageMap)[event] = stageMask; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4008 | return false; |
| 4009 | } |
| 4010 | |
| 4011 | void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4012 | VkPipelineStageFlags stageMask) { |
| 4013 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4014 | auto event_state = GetEventState(event); |
| 4015 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4016 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4017 | } |
| 4018 | cb_state->events.push_back(event); |
| 4019 | if (!cb_state->waitedEvents.count(event)) { |
| 4020 | cb_state->writeEventsBeforeWait.push_back(event); |
| 4021 | } |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4022 | cb_state->eventUpdates.emplace_back( |
| 4023 | [event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) { |
| 4024 | return SetEventStageMask(event, stageMask, localEventToStageMap); |
| 4025 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 4029 | VkPipelineStageFlags stageMask) { |
| 4030 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4031 | auto event_state = GetEventState(event); |
| 4032 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4033 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4034 | } |
| 4035 | cb_state->events.push_back(event); |
| 4036 | if (!cb_state->waitedEvents.count(event)) { |
| 4037 | cb_state->writeEventsBeforeWait.push_back(event); |
| 4038 | } |
| 4039 | |
| 4040 | cb_state->eventUpdates.emplace_back( |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4041 | [event](const ValidationStateTracker *, bool do_validate, EventToStageMap *localEventToStageMap) { |
| 4042 | return SetEventStageMask(event, VkPipelineStageFlags(0), localEventToStageMap); |
| 4043 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 4047 | VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask, |
| 4048 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 4049 | uint32_t bufferMemoryBarrierCount, |
| 4050 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 4051 | uint32_t imageMemoryBarrierCount, |
| 4052 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 4053 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4054 | for (uint32_t i = 0; i < eventCount; ++i) { |
| 4055 | auto event_state = GetEventState(pEvents[i]); |
| 4056 | if (event_state) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4057 | AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(pEvents[i], kVulkanObjectTypeEvent, event_state), |
| 4058 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4059 | } |
| 4060 | cb_state->waitedEvents.insert(pEvents[i]); |
| 4061 | cb_state->events.push_back(pEvents[i]); |
| 4062 | } |
| 4063 | } |
| 4064 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4065 | bool ValidationStateTracker::SetQueryState(QueryObject object, QueryState value, QueryMap *localQueryToStateMap) { |
| 4066 | (*localQueryToStateMap)[object] = value; |
| 4067 | return false; |
| 4068 | } |
| 4069 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4070 | bool ValidationStateTracker::SetQueryStateMulti(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, uint32_t perfPass, |
| 4071 | QueryState value, QueryMap *localQueryToStateMap) { |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4072 | for (uint32_t i = 0; i < queryCount; i++) { |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4073 | QueryObject object = QueryObject(QueryObject(queryPool, firstQuery + i), perfPass); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4074 | (*localQueryToStateMap)[object] = value; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4075 | } |
| 4076 | return false; |
| 4077 | } |
| 4078 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4079 | QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex, |
| 4080 | uint32_t perfPass) const { |
| 4081 | QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4082 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4083 | auto iter = localQueryToStateMap->find(query); |
| 4084 | if (iter != localQueryToStateMap->end()) return iter->second; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4085 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4086 | return QUERYSTATE_UNKNOWN; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | void ValidationStateTracker::RecordCmdBeginQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4090 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4091 | cb_state->activeQueries.insert(query_obj); |
| 4092 | cb_state->startedQueries.insert(query_obj); |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4093 | cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate, |
| 4094 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4095 | QueryMap *localQueryToStateMap) { |
| 4096 | SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_RUNNING, localQueryToStateMap); |
| 4097 | return false; |
| 4098 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4099 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 4100 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state), |
| 4101 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, |
| 4105 | VkFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4106 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4107 | QueryObject query = {queryPool, slot}; |
| 4108 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4109 | RecordCmdBeginQuery(cb_state, query); |
| 4110 | } |
| 4111 | |
| 4112 | void ValidationStateTracker::RecordCmdEndQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4113 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4114 | cb_state->activeQueries.erase(query_obj); |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4115 | cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate, |
| 4116 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4117 | QueryMap *localQueryToStateMap) { |
| 4118 | return SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap); |
| 4119 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4120 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 4121 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state), |
| 4122 | cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4126 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4127 | QueryObject query_obj = {queryPool, slot}; |
| 4128 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4129 | RecordCmdEndQuery(cb_state, query_obj); |
| 4130 | } |
| 4131 | |
| 4132 | void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4133 | uint32_t firstQuery, uint32_t queryCount) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4134 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4135 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4136 | |
Lionel Landwerlin | b1e5a42 | 2020-02-18 16:49:09 +0200 | [diff] [blame] | 4137 | for (uint32_t slot = firstQuery; slot < (firstQuery + queryCount); slot++) { |
| 4138 | QueryObject query = {queryPool, slot}; |
| 4139 | cb_state->resetQueries.insert(query); |
| 4140 | } |
| 4141 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 4142 | cb_state->queryUpdates.emplace_back([queryPool, firstQuery, queryCount](const ValidationStateTracker *device_data, |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4143 | bool do_validate, VkQueryPool &firstPerfQueryPool, |
| 4144 | uint32_t perfQueryPass, |
| 4145 | QueryMap *localQueryToStateMap) { |
| 4146 | return SetQueryStateMulti(queryPool, firstQuery, queryCount, perfQueryPass, QUERYSTATE_RESET, localQueryToStateMap); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4147 | }); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4148 | auto pool_state = GetQueryPoolState(queryPool); |
| 4149 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4150 | cb_state); |
| 4151 | } |
| 4152 | |
| 4153 | void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4154 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 4155 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 4156 | VkQueryResultFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4157 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4158 | auto cb_state = GetCBState(commandBuffer); |
| 4159 | auto dst_buff_state = GetBufferState(dstBuffer); |
| 4160 | AddCommandBufferBindingBuffer(cb_state, dst_buff_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4161 | auto pool_state = GetQueryPoolState(queryPool); |
| 4162 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4163 | cb_state); |
| 4164 | } |
| 4165 | |
| 4166 | void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 4167 | VkQueryPool queryPool, uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 4168 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4169 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 4170 | auto pool_state = GetQueryPoolState(queryPool); |
| 4171 | AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state), |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4172 | cb_state); |
| 4173 | QueryObject query = {queryPool, slot}; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4174 | cb_state->queryUpdates.emplace_back([query](const ValidationStateTracker *device_data, bool do_validate, |
| 4175 | VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass, |
| 4176 | QueryMap *localQueryToStateMap) { |
| 4177 | return SetQueryState(QueryObject(query, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap); |
| 4178 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo, |
| 4182 | const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer, |
| 4183 | VkResult result) { |
| 4184 | if (VK_SUCCESS != result) return; |
| 4185 | // Shadow create info and store in map |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 4186 | 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] | 4187 | |
| 4188 | if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) == 0) { |
| 4189 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 4190 | VkImageView view = pCreateInfo->pAttachments[i]; |
| 4191 | auto view_state = GetImageViewState(view); |
| 4192 | if (!view_state) { |
| 4193 | continue; |
| 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | frameBufferMap[*pFramebuffer] = std::move(fb_state); |
| 4198 | } |
| 4199 | |
| 4200 | void ValidationStateTracker::RecordRenderPassDAG(RenderPassCreateVersion rp_version, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4201 | RENDER_PASS_STATE *render_pass) { |
| 4202 | auto &subpass_to_node = render_pass->subpassToNode; |
| 4203 | subpass_to_node.resize(pCreateInfo->subpassCount); |
| 4204 | auto &self_dependencies = render_pass->self_dependencies; |
| 4205 | self_dependencies.resize(pCreateInfo->subpassCount); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4206 | auto &subpass_dependencies = render_pass->subpass_dependencies; |
| 4207 | subpass_dependencies.resize(pCreateInfo->subpassCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4208 | |
| 4209 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 4210 | subpass_to_node[i].pass = i; |
| 4211 | self_dependencies[i].clear(); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4212 | subpass_dependencies[i].pass = i; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4213 | } |
| 4214 | for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4215 | const auto &dependency = pCreateInfo->pDependencies[i]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4216 | const auto srcSubpass = dependency.srcSubpass; |
| 4217 | const auto dstSubpass = dependency.dstSubpass; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4218 | if ((dependency.srcSubpass != VK_SUBPASS_EXTERNAL) && (dependency.dstSubpass != VK_SUBPASS_EXTERNAL)) { |
| 4219 | if (dependency.srcSubpass == dependency.dstSubpass) { |
| 4220 | self_dependencies[dependency.srcSubpass].push_back(i); |
| 4221 | } else { |
| 4222 | subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass); |
| 4223 | subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass); |
| 4224 | } |
| 4225 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4226 | if (srcSubpass == VK_SUBPASS_EXTERNAL) { |
| 4227 | assert(dstSubpass != VK_SUBPASS_EXTERNAL); // this is invalid per VUID-VkSubpassDependency-srcSubpass-00865 |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4228 | subpass_dependencies[dstSubpass].barrier_from_external.emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4229 | } else if (dstSubpass == VK_SUBPASS_EXTERNAL) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4230 | subpass_dependencies[srcSubpass].barrier_to_external.emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4231 | } else if (dependency.srcSubpass != dependency.dstSubpass) { |
| 4232 | // ignore self dependencies in prev and next |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4233 | subpass_dependencies[srcSubpass].next[&subpass_dependencies[dstSubpass]].emplace_back(&dependency); |
| 4234 | subpass_dependencies[dstSubpass].prev[&subpass_dependencies[srcSubpass]].emplace_back(&dependency); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | // |
| 4239 | // Determine "asynchrononous" subpassess |
| 4240 | // syncronization is only interested in asyncronous stages *earlier* that the current one... so we'll only look towards those. |
| 4241 | // 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 |
| 4242 | // small and the K for |= from the prev is must less than for set, we'll accept the brute force. |
| 4243 | std::vector<std::vector<bool>> pass_depends(pCreateInfo->subpassCount); |
| 4244 | for (uint32_t i = 1; i < pCreateInfo->subpassCount; ++i) { |
| 4245 | auto &depends = pass_depends[i]; |
| 4246 | depends.resize(i); |
| 4247 | auto &subpass_dep = subpass_dependencies[i]; |
| 4248 | for (const auto &prev : subpass_dep.prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4249 | const auto prev_pass = prev.first->pass; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4250 | const auto &prev_depends = pass_depends[prev_pass]; |
| 4251 | for (uint32_t j = 0; j < prev_pass; j++) { |
| 4252 | depends[j] = depends[j] | prev_depends[j]; |
| 4253 | } |
| 4254 | depends[prev_pass] = true; |
| 4255 | } |
| 4256 | for (uint32_t pass = 0; pass < subpass_dep.pass; pass++) { |
| 4257 | if (!depends[pass]) { |
| 4258 | subpass_dep.async.push_back(pass); |
| 4259 | } |
| 4260 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4261 | } |
| 4262 | } |
| 4263 | |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4264 | static VkSubpassDependency2 ImplicitDependencyFromExternal(uint32_t subpass) { |
| 4265 | VkSubpassDependency2 from_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, |
| 4266 | nullptr, |
| 4267 | VK_SUBPASS_EXTERNAL, |
| 4268 | subpass, |
| 4269 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, |
| 4270 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4271 | 0, |
| 4272 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | |
| 4273 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 4274 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 4275 | 0, |
| 4276 | 0}; |
| 4277 | return from_external; |
| 4278 | } |
| 4279 | |
| 4280 | static VkSubpassDependency2 ImplicitDependencyToExternal(uint32_t subpass) { |
| 4281 | VkSubpassDependency2 to_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, |
| 4282 | nullptr, |
| 4283 | subpass, |
| 4284 | VK_SUBPASS_EXTERNAL, |
| 4285 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4286 | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, |
| 4287 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | |
| 4288 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | |
| 4289 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 4290 | 0, |
| 4291 | 0, |
| 4292 | 0}; |
| 4293 | return to_external; |
| 4294 | } |
| 4295 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4296 | void ValidationStateTracker::RecordCreateRenderPassState(RenderPassCreateVersion rp_version, |
| 4297 | std::shared_ptr<RENDER_PASS_STATE> &render_pass, |
| 4298 | VkRenderPass *pRenderPass) { |
| 4299 | render_pass->renderPass = *pRenderPass; |
| 4300 | auto create_info = render_pass->createInfo.ptr(); |
| 4301 | |
| 4302 | RecordRenderPassDAG(RENDER_PASS_VERSION_1, create_info, render_pass.get()); |
| 4303 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4304 | struct AttachmentTracker { // This is really only of local interest, but a bit big for a lambda |
| 4305 | RENDER_PASS_STATE *const rp; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4306 | std::vector<uint32_t> &first; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4307 | std::vector<bool> &first_is_transition; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4308 | std::vector<uint32_t> &last; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4309 | std::vector<std::vector<RENDER_PASS_STATE::AttachmentTransition>> &subpass_transitions; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4310 | std::unordered_map<uint32_t, bool> &first_read; |
| 4311 | const uint32_t attachment_count; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4312 | std::vector<VkImageLayout> attachment_layout; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4313 | std::vector<std::vector<VkImageLayout>> subpass_attachment_layout; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4314 | AttachmentTracker(std::shared_ptr<RENDER_PASS_STATE> &render_pass) |
| 4315 | : rp(render_pass.get()), |
| 4316 | first(rp->attachment_first_subpass), |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4317 | first_is_transition(rp->attachment_first_is_transition), |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4318 | last(rp->attachment_last_subpass), |
| 4319 | subpass_transitions(rp->subpass_transitions), |
| 4320 | first_read(rp->attachment_first_read), |
| 4321 | attachment_count(rp->createInfo.attachmentCount), |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4322 | attachment_layout(), |
| 4323 | subpass_attachment_layout() { |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4324 | first.resize(attachment_count, VK_SUBPASS_EXTERNAL); |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4325 | first_is_transition.resize(attachment_count, false); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4326 | last.resize(attachment_count, VK_SUBPASS_EXTERNAL); |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4327 | subpass_transitions.resize(rp->createInfo.subpassCount + 1); // Add an extra for EndRenderPass |
| 4328 | attachment_layout.reserve(attachment_count); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4329 | subpass_attachment_layout.resize(rp->createInfo.subpassCount); |
| 4330 | for (auto &subpass_layouts : subpass_attachment_layout) { |
| 4331 | subpass_layouts.resize(attachment_count, kInvalidLayout); |
| 4332 | } |
| 4333 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4334 | for (uint32_t j = 0; j < attachment_count; j++) { |
| 4335 | attachment_layout.push_back(rp->createInfo.pAttachments[j].initialLayout); |
| 4336 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4337 | } |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4338 | |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4339 | void Update(uint32_t subpass, const VkAttachmentReference2 *attach_ref, uint32_t count, bool is_read) { |
| 4340 | if (nullptr == attach_ref) return; |
| 4341 | for (uint32_t j = 0; j < count; ++j) { |
| 4342 | const auto attachment = attach_ref[j].attachment; |
| 4343 | if (attachment != VK_ATTACHMENT_UNUSED) { |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4344 | const auto layout = attach_ref[j].layout; |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4345 | // Take advantage of the fact that insert won't overwrite, so we'll only write the first time. |
| 4346 | first_read.insert(std::make_pair(attachment, is_read)); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4347 | if (first[attachment] == VK_SUBPASS_EXTERNAL) { |
| 4348 | first[attachment] = subpass; |
| 4349 | const auto initial_layout = rp->createInfo.pAttachments[attachment].initialLayout; |
John Zulauf | 1507ee4 | 2020-05-18 11:33:09 -0600 | [diff] [blame] | 4350 | if (initial_layout != layout) { |
| 4351 | subpass_transitions[subpass].emplace_back(VK_SUBPASS_EXTERNAL, attachment, initial_layout, layout); |
| 4352 | first_is_transition[attachment] = true; |
| 4353 | } |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4354 | } |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4355 | last[attachment] = subpass; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4356 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4357 | for (const auto &prev : rp->subpass_dependencies[subpass].prev) { |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4358 | const auto prev_pass = prev.first->pass; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4359 | const auto prev_layout = subpass_attachment_layout[prev_pass][attachment]; |
| 4360 | if ((prev_layout != kInvalidLayout) && (prev_layout != layout)) { |
| 4361 | subpass_transitions[subpass].emplace_back(prev_pass, attachment, prev_layout, layout); |
| 4362 | } |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4363 | } |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4364 | attachment_layout[attachment] = layout; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | void FinalTransitions() { |
| 4369 | auto &final_transitions = subpass_transitions[rp->createInfo.subpassCount]; |
| 4370 | |
| 4371 | for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) { |
| 4372 | const auto final_layout = rp->createInfo.pAttachments[attachment].finalLayout; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 4373 | // Add final transitions for attachments that were used and change layout. |
| 4374 | if ((last[attachment] != VK_SUBPASS_EXTERNAL) && final_layout != attachment_layout[attachment]) { |
| 4375 | final_transitions.emplace_back(last[attachment], attachment, attachment_layout[attachment], final_layout); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4376 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4377 | } |
| 4378 | } |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4379 | }; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4380 | AttachmentTracker attachment_tracker(render_pass); |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4381 | |
| 4382 | for (uint32_t subpass_index = 0; subpass_index < create_info->subpassCount; ++subpass_index) { |
| 4383 | const VkSubpassDescription2KHR &subpass = create_info->pSubpasses[subpass_index]; |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4384 | attachment_tracker.Update(subpass_index, subpass.pColorAttachments, subpass.colorAttachmentCount, false); |
| 4385 | attachment_tracker.Update(subpass_index, subpass.pResolveAttachments, subpass.colorAttachmentCount, false); |
| 4386 | attachment_tracker.Update(subpass_index, subpass.pDepthStencilAttachment, 1, false); |
| 4387 | attachment_tracker.Update(subpass_index, subpass.pInputAttachments, subpass.inputAttachmentCount, true); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4388 | } |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4389 | attachment_tracker.FinalTransitions(); |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4390 | |
John Zulauf | bb9f07f | 2020-03-19 16:53:06 -0600 | [diff] [blame] | 4391 | // Add implicit dependencies |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4392 | for (uint32_t attachment = 0; attachment < attachment_tracker.attachment_count; attachment++) { |
| 4393 | const auto first_use = attachment_tracker.first[attachment]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4394 | if (first_use != VK_SUBPASS_EXTERNAL) { |
| 4395 | auto &subpass_dep = render_pass->subpass_dependencies[first_use]; |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4396 | if (subpass_dep.barrier_from_external.size() == 0) { |
| 4397 | // Add implicit from barrier if they're aren't any |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4398 | subpass_dep.implicit_barrier_from_external.reset( |
| 4399 | new VkSubpassDependency2(ImplicitDependencyFromExternal(first_use))); |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4400 | 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] | 4401 | } |
| 4402 | } |
| 4403 | |
John Zulauf | 8863c33 | 2020-03-20 10:34:33 -0600 | [diff] [blame] | 4404 | const auto last_use = attachment_tracker.last[attachment]; |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4405 | if (last_use != VK_SUBPASS_EXTERNAL) { |
| 4406 | auto &subpass_dep = render_pass->subpass_dependencies[last_use]; |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4407 | if (render_pass->subpass_dependencies[last_use].barrier_to_external.size() == 0) { |
| 4408 | // Add implicit to barrier if they're aren't any |
John Zulauf | 4aff5d9 | 2020-02-21 08:29:35 -0700 | [diff] [blame] | 4409 | subpass_dep.implicit_barrier_to_external.reset(new VkSubpassDependency2(ImplicitDependencyToExternal(last_use))); |
John Zulauf | baea94f | 2020-09-15 17:55:16 -0600 | [diff] [blame] | 4410 | 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] | 4411 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | // Even though render_pass is an rvalue-ref parameter, still must move s.t. move assignment is invoked. |
| 4416 | renderPassMap[*pRenderPass] = std::move(render_pass); |
| 4417 | } |
| 4418 | |
| 4419 | // Style note: |
| 4420 | // Use of rvalue reference exceeds reccommended usage of rvalue refs in google style guide, but intentionally forces caller to move |
| 4421 | // or copy. This is clearer than passing a pointer to shared_ptr and avoids the atomic increment/decrement of shared_ptr copy |
| 4422 | // construction or assignment. |
| 4423 | void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
| 4424 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4425 | VkResult result) { |
| 4426 | if (VK_SUCCESS != result) return; |
| 4427 | auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo); |
| 4428 | RecordCreateRenderPassState(RENDER_PASS_VERSION_1, render_pass_state, pRenderPass); |
| 4429 | } |
| 4430 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4431 | void ValidationStateTracker::RecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4432 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4433 | VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4434 | if (VK_SUCCESS != result) return; |
| 4435 | auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo); |
| 4436 | RecordCreateRenderPassState(RENDER_PASS_VERSION_2, render_pass_state, pRenderPass); |
| 4437 | } |
| 4438 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4439 | void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4440 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4441 | VkResult result) { |
| 4442 | RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result); |
| 4443 | } |
| 4444 | |
| 4445 | void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo, |
| 4446 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 4447 | VkResult result) { |
| 4448 | RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result); |
| 4449 | } |
| 4450 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4451 | void ValidationStateTracker::RecordCmdBeginRenderPassState(VkCommandBuffer commandBuffer, |
| 4452 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4453 | const VkSubpassContents contents) { |
| 4454 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4455 | auto render_pass_state = pRenderPassBegin ? GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass) : nullptr; |
| 4456 | auto framebuffer = pRenderPassBegin ? GetShared<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer) : nullptr; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4457 | |
| 4458 | if (render_pass_state) { |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4459 | cb_state->activeFramebuffer = framebuffer; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4460 | cb_state->activeRenderPass = render_pass_state; |
Tony-LunarG | 61e7c0c | 2020-03-03 16:09:11 -0700 | [diff] [blame] | 4461 | cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(pRenderPassBegin); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4462 | cb_state->activeSubpass = 0; |
| 4463 | cb_state->activeSubpassContents = contents; |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4464 | if (framebuffer) cb_state->framebuffers.insert(framebuffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4465 | // Connect this framebuffer and its children to this cmdBuffer |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4466 | AddFramebufferBinding(cb_state, framebuffer.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4467 | // Connect this RP to cmdBuffer |
locke-lunarg | aecf215 | 2020-05-12 17:15:41 -0600 | [diff] [blame] | 4468 | AddCommandBufferBinding( |
| 4469 | render_pass_state->cb_bindings, |
| 4470 | VulkanTypedHandle(render_pass_state->renderPass, kVulkanObjectTypeRenderPass, render_pass_state.get()), cb_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4471 | |
| 4472 | auto chained_device_group_struct = lvl_find_in_chain<VkDeviceGroupRenderPassBeginInfo>(pRenderPassBegin->pNext); |
| 4473 | if (chained_device_group_struct) { |
| 4474 | cb_state->active_render_pass_device_mask = chained_device_group_struct->deviceMask; |
| 4475 | } else { |
| 4476 | cb_state->active_render_pass_device_mask = cb_state->initial_device_mask; |
| 4477 | } |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 4478 | |
| 4479 | cb_state->imagelessFramebufferAttachments.clear(); |
| 4480 | auto attachment_info_struct = lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext); |
| 4481 | if (attachment_info_struct) { |
| 4482 | for (uint32_t i = 0; i < attachment_info_struct->attachmentCount; i++) { |
| 4483 | IMAGE_VIEW_STATE *img_view_state = GetImageViewState(attachment_info_struct->pAttachments[i]); |
| 4484 | cb_state->imagelessFramebufferAttachments.push_back(img_view_state); |
| 4485 | } |
| 4486 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4487 | } |
| 4488 | } |
| 4489 | |
| 4490 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, |
| 4491 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4492 | VkSubpassContents contents) { |
| 4493 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, contents); |
| 4494 | } |
| 4495 | |
| 4496 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4497 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4498 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) { |
| 4499 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 4500 | } |
| 4501 | |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 4502 | void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 4503 | uint32_t counterBufferCount, |
| 4504 | const VkBuffer *pCounterBuffers, |
| 4505 | const VkDeviceSize *pCounterBufferOffsets) { |
| 4506 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4507 | |
| 4508 | cb_state->transform_feedback_active = true; |
| 4509 | } |
| 4510 | |
| 4511 | void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 4512 | uint32_t counterBufferCount, const VkBuffer *pCounterBuffers, |
| 4513 | const VkDeviceSize *pCounterBufferOffsets) { |
| 4514 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4515 | |
| 4516 | cb_state->transform_feedback_active = false; |
| 4517 | } |
| 4518 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4519 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, |
| 4520 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 4521 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo) { |
| 4522 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 4523 | } |
| 4524 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4525 | void ValidationStateTracker::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4526 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4527 | cb_state->activeSubpass++; |
| 4528 | cb_state->activeSubpassContents = contents; |
| 4529 | } |
| 4530 | |
| 4531 | void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 4532 | RecordCmdNextSubpass(commandBuffer, contents); |
| 4533 | } |
| 4534 | |
| 4535 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, |
| 4536 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 4537 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4538 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 4539 | } |
| 4540 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4541 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, |
| 4542 | const VkSubpassBeginInfoKHR *pSubpassBeginInfo, |
| 4543 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4544 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 4545 | } |
| 4546 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4547 | void ValidationStateTracker::RecordCmdEndRenderPassState(VkCommandBuffer commandBuffer) { |
| 4548 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4549 | cb_state->activeRenderPass = nullptr; |
| 4550 | cb_state->activeSubpass = 0; |
| 4551 | cb_state->activeFramebuffer = VK_NULL_HANDLE; |
Lionel Landwerlin | 484d10f | 2020-04-24 01:34:47 +0300 | [diff] [blame] | 4552 | cb_state->imagelessFramebufferAttachments.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
| 4556 | RecordCmdEndRenderPassState(commandBuffer); |
| 4557 | } |
| 4558 | |
| 4559 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 4560 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4561 | RecordCmdEndRenderPassState(commandBuffer); |
| 4562 | } |
| 4563 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4564 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, |
| 4565 | const VkSubpassEndInfoKHR *pSubpassEndInfo) { |
| 4566 | RecordCmdEndRenderPassState(commandBuffer); |
| 4567 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4568 | void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, |
| 4569 | const VkCommandBuffer *pCommandBuffers) { |
| 4570 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4571 | |
| 4572 | CMD_BUFFER_STATE *sub_cb_state = NULL; |
| 4573 | for (uint32_t i = 0; i < commandBuffersCount; i++) { |
| 4574 | sub_cb_state = GetCBState(pCommandBuffers[i]); |
| 4575 | assert(sub_cb_state); |
| 4576 | if (!(sub_cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) { |
| 4577 | if (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) { |
| 4578 | // TODO: Because this is a state change, clearing the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT needs to be moved |
| 4579 | // from the validation step to the recording step |
| 4580 | cb_state->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | // Propagate inital layout and current layout state to the primary cmd buffer |
| 4585 | // NOTE: The update/population of the image_layout_map is done in CoreChecks, but for other classes derived from |
| 4586 | // ValidationStateTracker these maps will be empty, so leaving the propagation in the the state tracker should be a no-op |
| 4587 | // for those other classes. |
| 4588 | for (const auto &sub_layout_map_entry : sub_cb_state->image_layout_map) { |
| 4589 | const auto image = sub_layout_map_entry.first; |
| 4590 | const auto *image_state = GetImageState(image); |
| 4591 | if (!image_state) continue; // Can't set layouts of a dead image |
| 4592 | |
| 4593 | auto *cb_subres_map = GetImageSubresourceLayoutMap(cb_state, *image_state); |
| 4594 | const auto *sub_cb_subres_map = sub_layout_map_entry.second.get(); |
| 4595 | assert(cb_subres_map && sub_cb_subres_map); // Non const get and map traversal should never be null |
| 4596 | cb_subres_map->UpdateFrom(*sub_cb_subres_map); |
| 4597 | } |
| 4598 | |
| 4599 | sub_cb_state->primaryCommandBuffer = cb_state->commandBuffer; |
| 4600 | cb_state->linkedCommandBuffers.insert(sub_cb_state); |
| 4601 | sub_cb_state->linkedCommandBuffers.insert(cb_state); |
| 4602 | for (auto &function : sub_cb_state->queryUpdates) { |
| 4603 | cb_state->queryUpdates.push_back(function); |
| 4604 | } |
| 4605 | for (auto &function : sub_cb_state->queue_submit_functions) { |
| 4606 | cb_state->queue_submit_functions.push_back(function); |
| 4607 | } |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, |
| 4612 | VkFlags flags, void **ppData, VkResult result) { |
| 4613 | if (VK_SUCCESS != result) return; |
| 4614 | RecordMappedMemory(mem, offset, size, ppData); |
| 4615 | } |
| 4616 | |
| 4617 | void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) { |
| 4618 | auto mem_info = GetDevMemState(mem); |
| 4619 | if (mem_info) { |
| 4620 | mem_info->mapped_range = MemRange(); |
| 4621 | mem_info->p_driver_data = nullptr; |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) { |
| 4626 | IMAGE_STATE *image_state = GetImageState(bindInfo.image); |
| 4627 | if (image_state) { |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 4628 | // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory. |
| 4629 | // See: VUID-vkGetImageSubresourceLayout-image-01895 |
| 4630 | image_state->fragment_encoder = |
| 4631 | 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] | 4632 | const auto swapchain_info = lvl_find_in_chain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext); |
| 4633 | if (swapchain_info) { |
| 4634 | auto swapchain = GetSwapchainState(swapchain_info->swapchain); |
| 4635 | if (swapchain) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 4636 | swapchain->images[swapchain_info->imageIndex].bound_images.emplace(image_state->image); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4637 | image_state->bind_swapchain = swapchain_info->swapchain; |
| 4638 | image_state->bind_swapchain_imageIndex = swapchain_info->imageIndex; |
| 4639 | } |
| 4640 | } else { |
| 4641 | // Track bound memory range information |
| 4642 | auto mem_info = GetDevMemState(bindInfo.memory); |
| 4643 | if (mem_info) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 4644 | InsertImageMemoryRange(bindInfo.image, mem_info, bindInfo.memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | // Track objects tied to memory |
| 4648 | SetMemBinding(bindInfo.memory, image_state, bindInfo.memoryOffset, |
| 4649 | VulkanTypedHandle(bindInfo.image, kVulkanObjectTypeImage)); |
| 4650 | } |
Tony-LunarG | 330cf4c | 2020-03-04 16:29:03 -0700 | [diff] [blame] | 4651 | if ((image_state->createInfo.flags & VK_IMAGE_CREATE_ALIAS_BIT) || swapchain_info) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4652 | AddAliasingImage(image_state); |
| 4653 | } |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem, |
| 4658 | VkDeviceSize memoryOffset, VkResult result) { |
| 4659 | if (VK_SUCCESS != result) return; |
| 4660 | VkBindImageMemoryInfo bindInfo = {}; |
| 4661 | bindInfo.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO; |
| 4662 | bindInfo.image = image; |
| 4663 | bindInfo.memory = mem; |
| 4664 | bindInfo.memoryOffset = memoryOffset; |
| 4665 | UpdateBindImageMemoryState(bindInfo); |
| 4666 | } |
| 4667 | |
| 4668 | void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
| 4669 | const VkBindImageMemoryInfoKHR *pBindInfos, VkResult result) { |
| 4670 | if (VK_SUCCESS != result) return; |
| 4671 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 4672 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 4673 | } |
| 4674 | } |
| 4675 | |
| 4676 | void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
| 4677 | const VkBindImageMemoryInfoKHR *pBindInfos, VkResult result) { |
| 4678 | if (VK_SUCCESS != result) return; |
| 4679 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 4680 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) { |
| 4685 | auto event_state = GetEventState(event); |
| 4686 | if (event_state) { |
| 4687 | event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT; |
| 4688 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device, |
| 4692 | const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo, |
| 4693 | VkResult result) { |
| 4694 | if (VK_SUCCESS != result) return; |
| 4695 | RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType, |
| 4696 | pImportSemaphoreFdInfo->flags); |
| 4697 | } |
| 4698 | |
| 4699 | void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore, |
| 4700 | VkExternalSemaphoreHandleTypeFlagBitsKHR handle_type) { |
| 4701 | SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore); |
| 4702 | if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR) { |
| 4703 | // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference |
| 4704 | semaphore_state->scope = kSyncScopeExternalPermanent; |
| 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 4709 | void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR( |
| 4710 | VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) { |
| 4711 | if (VK_SUCCESS != result) return; |
| 4712 | RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType, |
| 4713 | pImportSemaphoreWin32HandleInfo->flags); |
| 4714 | } |
| 4715 | |
| 4716 | void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device, |
| 4717 | const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 4718 | HANDLE *pHandle, VkResult result) { |
| 4719 | if (VK_SUCCESS != result) return; |
| 4720 | RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType); |
| 4721 | } |
| 4722 | |
| 4723 | void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR( |
| 4724 | VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) { |
| 4725 | if (VK_SUCCESS != result) return; |
| 4726 | RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType, |
| 4727 | pImportFenceWin32HandleInfo->flags); |
| 4728 | } |
| 4729 | |
| 4730 | void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device, |
| 4731 | const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 4732 | HANDLE *pHandle, VkResult result) { |
| 4733 | if (VK_SUCCESS != result) return; |
| 4734 | RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType); |
| 4735 | } |
| 4736 | #endif |
| 4737 | |
| 4738 | void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 4739 | VkResult result) { |
| 4740 | if (VK_SUCCESS != result) return; |
| 4741 | RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType); |
| 4742 | } |
| 4743 | |
| 4744 | void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBitsKHR handle_type, |
| 4745 | VkFenceImportFlagsKHR flags) { |
| 4746 | FENCE_STATE *fence_node = GetFenceState(fence); |
| 4747 | if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) { |
| 4748 | if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR || flags & VK_FENCE_IMPORT_TEMPORARY_BIT_KHR) && |
| 4749 | fence_node->scope == kSyncScopeInternal) { |
| 4750 | fence_node->scope = kSyncScopeExternalTemporary; |
| 4751 | } else { |
| 4752 | fence_node->scope = kSyncScopeExternalPermanent; |
| 4753 | } |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo, |
| 4758 | VkResult result) { |
| 4759 | if (VK_SUCCESS != result) return; |
| 4760 | RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags); |
| 4761 | } |
| 4762 | |
| 4763 | void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBitsKHR handle_type) { |
| 4764 | FENCE_STATE *fence_state = GetFenceState(fence); |
| 4765 | if (fence_state) { |
| 4766 | if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR) { |
| 4767 | // Export with reference transference becomes external |
| 4768 | fence_state->scope = kSyncScopeExternalPermanent; |
| 4769 | } else if (fence_state->scope == kSyncScopeInternal) { |
| 4770 | // Export with copy transference has a side effect of resetting the fence |
| 4771 | fence_state->state = FENCE_UNSIGNALED; |
| 4772 | } |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 4777 | VkResult result) { |
| 4778 | if (VK_SUCCESS != result) return; |
| 4779 | RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType); |
| 4780 | } |
| 4781 | |
| 4782 | void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo, |
| 4783 | const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) { |
| 4784 | if (VK_SUCCESS != result) return; |
| 4785 | eventMap[*pEvent].write_in_use = 0; |
| 4786 | eventMap[*pEvent].stageMask = VkPipelineStageFlags(0); |
| 4787 | } |
| 4788 | |
| 4789 | void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 4790 | VkSwapchainKHR *pSwapchain, SURFACE_STATE *surface_state, |
| 4791 | SWAPCHAIN_NODE *old_swapchain_state) { |
| 4792 | if (VK_SUCCESS == result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4793 | auto swapchain_state = std::make_shared<SWAPCHAIN_NODE>(pCreateInfo, *pSwapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4794 | if (VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR == pCreateInfo->presentMode || |
| 4795 | VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR == pCreateInfo->presentMode) { |
| 4796 | swapchain_state->shared_presentable = true; |
| 4797 | } |
| 4798 | surface_state->swapchain = swapchain_state.get(); |
| 4799 | swapchainMap[*pSwapchain] = std::move(swapchain_state); |
| 4800 | } else { |
| 4801 | surface_state->swapchain = nullptr; |
| 4802 | } |
| 4803 | // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired |
| 4804 | if (old_swapchain_state) { |
| 4805 | old_swapchain_state->retired = true; |
| 4806 | } |
| 4807 | return; |
| 4808 | } |
| 4809 | |
| 4810 | void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 4811 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain, |
| 4812 | VkResult result) { |
| 4813 | auto surface_state = GetSurfaceState(pCreateInfo->surface); |
| 4814 | auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain); |
| 4815 | RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, surface_state, old_swapchain_state); |
| 4816 | } |
| 4817 | |
| 4818 | void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 4819 | const VkAllocationCallbacks *pAllocator) { |
| 4820 | if (!swapchain) return; |
| 4821 | auto swapchain_data = GetSwapchainState(swapchain); |
| 4822 | if (swapchain_data) { |
| 4823 | for (const auto &swapchain_image : swapchain_data->images) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 4824 | ClearMemoryObjectBindings(VulkanTypedHandle(swapchain_image.image, kVulkanObjectTypeImage)); |
| 4825 | imageMap.erase(swapchain_image.image); |
| 4826 | RemoveAliasingImages(swapchain_image.bound_images); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | auto surface_state = GetSurfaceState(swapchain_data->createInfo.surface); |
| 4830 | if (surface_state) { |
| 4831 | if (surface_state->swapchain == swapchain_data) surface_state->swapchain = nullptr; |
| 4832 | } |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4833 | swapchain_data->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4834 | swapchainMap.erase(swapchain); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) { |
| 4839 | // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?) |
| 4840 | for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) { |
| 4841 | auto pSemaphore = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]); |
| 4842 | if (pSemaphore) { |
| 4843 | pSemaphore->signaler.first = VK_NULL_HANDLE; |
| 4844 | pSemaphore->signaled = false; |
| 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 4849 | // 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 |
| 4850 | // confused itself just as much. |
| 4851 | auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 4852 | if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen. |
| 4853 | // Mark the image as having been released to the WSI |
| 4854 | auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]); |
| 4855 | if (swapchain_data && (swapchain_data->images.size() > pPresentInfo->pImageIndices[i])) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 4856 | auto image = swapchain_data->images[pPresentInfo->pImageIndices[i]].image; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4857 | auto image_state = GetImageState(image); |
| 4858 | if (image_state) { |
| 4859 | image_state->acquired = false; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 4860 | if (image_state->shared_presentable) { |
| 4861 | image_state->layout_locked = true; |
| 4862 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4863 | } |
| 4864 | } |
| 4865 | } |
| 4866 | // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and |
| 4867 | // its semaphore waits) /never/ participate in any completion proof. |
| 4868 | } |
| 4869 | |
| 4870 | void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 4871 | const VkSwapchainCreateInfoKHR *pCreateInfos, |
| 4872 | const VkAllocationCallbacks *pAllocator, |
| 4873 | VkSwapchainKHR *pSwapchains, VkResult result) { |
| 4874 | if (pCreateInfos) { |
| 4875 | for (uint32_t i = 0; i < swapchainCount; i++) { |
| 4876 | auto surface_state = GetSurfaceState(pCreateInfos[i].surface); |
| 4877 | auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain); |
| 4878 | RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], surface_state, old_swapchain_state); |
| 4879 | } |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 4884 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) { |
| 4885 | auto pFence = GetFenceState(fence); |
| 4886 | if (pFence && pFence->scope == kSyncScopeInternal) { |
| 4887 | // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary |
| 4888 | // import |
| 4889 | pFence->state = FENCE_INFLIGHT; |
| 4890 | pFence->signaler.first = VK_NULL_HANDLE; // ANI isn't on a queue, so this can't participate in a completion proof. |
| 4891 | } |
| 4892 | |
| 4893 | auto pSemaphore = GetSemaphoreState(semaphore); |
| 4894 | if (pSemaphore && pSemaphore->scope == kSyncScopeInternal) { |
| 4895 | // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a |
| 4896 | // temporary import |
| 4897 | pSemaphore->signaled = true; |
| 4898 | pSemaphore->signaler.first = VK_NULL_HANDLE; |
| 4899 | } |
| 4900 | |
| 4901 | // Mark the image as acquired. |
| 4902 | auto swapchain_data = GetSwapchainState(swapchain); |
| 4903 | if (swapchain_data && (swapchain_data->images.size() > *pImageIndex)) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 4904 | auto image = swapchain_data->images[*pImageIndex].image; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4905 | auto image_state = GetImageState(image); |
| 4906 | if (image_state) { |
| 4907 | image_state->acquired = true; |
| 4908 | image_state->shared_presentable = swapchain_data->shared_presentable; |
| 4909 | } |
| 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 4914 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex, |
| 4915 | VkResult result) { |
| 4916 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 4917 | RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex); |
| 4918 | } |
| 4919 | |
| 4920 | void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo, |
| 4921 | uint32_t *pImageIndex, VkResult result) { |
| 4922 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 4923 | RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore, |
| 4924 | pAcquireInfo->fence, pImageIndex); |
| 4925 | } |
| 4926 | |
| 4927 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 4928 | VkPhysicalDevice *pPhysicalDevices, VkResult result) { |
| 4929 | if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) { |
| 4930 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 4931 | auto &phys_device_state = physical_device_map[pPhysicalDevices[i]]; |
| 4932 | phys_device_state.phys_device = pPhysicalDevices[i]; |
| 4933 | // Init actual features for each physical device |
| 4934 | DispatchGetPhysicalDeviceFeatures(pPhysicalDevices[i], &phys_device_state.features2.features); |
| 4935 | } |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | // Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 4940 | static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count, |
| 4941 | VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 4942 | pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count); |
| 4943 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4944 | if (pQueueFamilyProperties) { // Save queue family properties |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4945 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 4946 | for (uint32_t i = 0; i < count; ++i) { |
| 4947 | pd_state->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties; |
| 4948 | } |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 4953 | uint32_t *pQueueFamilyPropertyCount, |
| 4954 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
| 4955 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 4956 | assert(physical_device_state); |
| 4957 | VkQueueFamilyProperties2KHR *pqfp = nullptr; |
| 4958 | std::vector<VkQueueFamilyProperties2KHR> qfp; |
| 4959 | qfp.resize(*pQueueFamilyPropertyCount); |
| 4960 | if (pQueueFamilyProperties) { |
| 4961 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) { |
| 4962 | qfp[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR; |
| 4963 | qfp[i].pNext = nullptr; |
| 4964 | qfp[i].queueFamilyProperties = pQueueFamilyProperties[i]; |
| 4965 | } |
| 4966 | pqfp = qfp.data(); |
| 4967 | } |
| 4968 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, pqfp); |
| 4969 | } |
| 4970 | |
| 4971 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2( |
| 4972 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 4973 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 4974 | assert(physical_device_state); |
| 4975 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 4976 | pQueueFamilyProperties); |
| 4977 | } |
| 4978 | |
| 4979 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR( |
| 4980 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 4981 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 4982 | assert(physical_device_state); |
| 4983 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 4984 | pQueueFamilyProperties); |
| 4985 | } |
| 4986 | void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, |
| 4987 | const VkAllocationCallbacks *pAllocator) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4988 | if (!surface) return; |
| 4989 | auto surface_state = GetSurfaceState(surface); |
| 4990 | surface_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4991 | surface_map.erase(surface); |
| 4992 | } |
| 4993 | |
| 4994 | void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4995 | surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance, |
| 4999 | const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, |
| 5000 | const VkAllocationCallbacks *pAllocator, |
| 5001 | VkSurfaceKHR *pSurface, VkResult result) { |
| 5002 | if (VK_SUCCESS != result) return; |
| 5003 | RecordVulkanSurface(pSurface); |
| 5004 | } |
| 5005 | |
| 5006 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 5007 | void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance, |
| 5008 | const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 5009 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5010 | VkResult result) { |
| 5011 | if (VK_SUCCESS != result) return; |
| 5012 | RecordVulkanSurface(pSurface); |
| 5013 | } |
| 5014 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 5015 | |
| 5016 | #ifdef VK_USE_PLATFORM_IOS_MVK |
| 5017 | void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo, |
| 5018 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5019 | VkResult result) { |
| 5020 | if (VK_SUCCESS != result) return; |
| 5021 | RecordVulkanSurface(pSurface); |
| 5022 | } |
| 5023 | #endif // VK_USE_PLATFORM_IOS_MVK |
| 5024 | |
| 5025 | #ifdef VK_USE_PLATFORM_MACOS_MVK |
| 5026 | void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance, |
| 5027 | const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, |
| 5028 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5029 | VkResult result) { |
| 5030 | if (VK_SUCCESS != result) return; |
| 5031 | RecordVulkanSurface(pSurface); |
| 5032 | } |
| 5033 | #endif // VK_USE_PLATFORM_MACOS_MVK |
| 5034 | |
Jeremy Kniager | f33a67c | 2019-12-09 09:44:39 -0700 | [diff] [blame] | 5035 | #ifdef VK_USE_PLATFORM_METAL_EXT |
| 5036 | void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance, |
| 5037 | const VkMetalSurfaceCreateInfoEXT *pCreateInfo, |
| 5038 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5039 | VkResult result) { |
| 5040 | if (VK_SUCCESS != result) return; |
| 5041 | RecordVulkanSurface(pSurface); |
| 5042 | } |
| 5043 | #endif // VK_USE_PLATFORM_METAL_EXT |
| 5044 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5045 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 5046 | void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance, |
| 5047 | const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 5048 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5049 | VkResult result) { |
| 5050 | if (VK_SUCCESS != result) return; |
| 5051 | RecordVulkanSurface(pSurface); |
| 5052 | } |
| 5053 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 5054 | |
| 5055 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 5056 | void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance, |
| 5057 | const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 5058 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5059 | VkResult result) { |
| 5060 | if (VK_SUCCESS != result) return; |
| 5061 | RecordVulkanSurface(pSurface); |
| 5062 | } |
| 5063 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 5064 | |
| 5065 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 5066 | void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, |
| 5067 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5068 | VkResult result) { |
| 5069 | if (VK_SUCCESS != result) return; |
| 5070 | RecordVulkanSurface(pSurface); |
| 5071 | } |
| 5072 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 5073 | |
| 5074 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 5075 | void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, |
| 5076 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5077 | VkResult result) { |
| 5078 | if (VK_SUCCESS != result) return; |
| 5079 | RecordVulkanSurface(pSurface); |
| 5080 | } |
| 5081 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 5082 | |
Niklas Haas | 8b84af1 | 2020-04-19 22:20:11 +0200 | [diff] [blame] | 5083 | void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance, |
| 5084 | const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, |
| 5085 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 5086 | VkResult result) { |
| 5087 | if (VK_SUCCESS != result) return; |
| 5088 | RecordVulkanSurface(pSurface); |
| 5089 | } |
| 5090 | |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5091 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5092 | VkPhysicalDeviceFeatures *pFeatures) { |
| 5093 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Yilong Li | 358152a | 2020-07-08 02:16:45 -0700 | [diff] [blame] | 5094 | // Reset the features2 safe struct before setting up the features field. |
| 5095 | physical_device_state->features2 = safe_VkPhysicalDeviceFeatures2(); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5096 | physical_device_state->features2.features = *pFeatures; |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5100 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 5101 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5102 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5106 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 5107 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 5108 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 5109 | } |
| 5110 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5111 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 5112 | VkSurfaceKHR surface, |
| 5113 | VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, |
| 5114 | VkResult result) { |
| 5115 | if (VK_SUCCESS != result) return; |
| 5116 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5117 | physical_device_state->surfaceCapabilities = *pSurfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5118 | |
| 5119 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5120 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 5124 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 5125 | VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) { |
| 5126 | if (VK_SUCCESS != result) return; |
| 5127 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5128 | physical_device_state->surfaceCapabilities = pSurfaceCapabilities->surfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5129 | |
| 5130 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5131 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 5135 | VkSurfaceKHR surface, |
| 5136 | VkSurfaceCapabilities2EXT *pSurfaceCapabilities, |
| 5137 | VkResult result) { |
| 5138 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5139 | physical_device_state->surfaceCapabilities.minImageCount = pSurfaceCapabilities->minImageCount; |
| 5140 | physical_device_state->surfaceCapabilities.maxImageCount = pSurfaceCapabilities->maxImageCount; |
| 5141 | physical_device_state->surfaceCapabilities.currentExtent = pSurfaceCapabilities->currentExtent; |
| 5142 | physical_device_state->surfaceCapabilities.minImageExtent = pSurfaceCapabilities->minImageExtent; |
| 5143 | physical_device_state->surfaceCapabilities.maxImageExtent = pSurfaceCapabilities->maxImageExtent; |
| 5144 | physical_device_state->surfaceCapabilities.maxImageArrayLayers = pSurfaceCapabilities->maxImageArrayLayers; |
| 5145 | physical_device_state->surfaceCapabilities.supportedTransforms = pSurfaceCapabilities->supportedTransforms; |
| 5146 | physical_device_state->surfaceCapabilities.currentTransform = pSurfaceCapabilities->currentTransform; |
| 5147 | physical_device_state->surfaceCapabilities.supportedCompositeAlpha = pSurfaceCapabilities->supportedCompositeAlpha; |
| 5148 | physical_device_state->surfaceCapabilities.supportedUsageFlags = pSurfaceCapabilities->supportedUsageFlags; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5149 | |
| 5150 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 5151 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, |
| 5155 | uint32_t queueFamilyIndex, VkSurfaceKHR surface, |
| 5156 | VkBool32 *pSupported, VkResult result) { |
| 5157 | if (VK_SUCCESS != result) return; |
| 5158 | auto surface_state = GetSurfaceState(surface); |
| 5159 | surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE); |
| 5160 | } |
| 5161 | |
| 5162 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 5163 | VkSurfaceKHR surface, |
| 5164 | uint32_t *pPresentModeCount, |
| 5165 | VkPresentModeKHR *pPresentModes, |
| 5166 | VkResult result) { |
| 5167 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5168 | |
| 5169 | // TODO: This isn't quite right -- available modes may differ by surface AND physical device. |
| 5170 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5171 | |
| 5172 | if (*pPresentModeCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5173 | if (*pPresentModeCount > physical_device_state->present_modes.size()) |
| 5174 | physical_device_state->present_modes.resize(*pPresentModeCount); |
| 5175 | } |
| 5176 | if (pPresentModes) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5177 | for (uint32_t i = 0; i < *pPresentModeCount; i++) { |
| 5178 | physical_device_state->present_modes[i] = pPresentModes[i]; |
| 5179 | } |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 5184 | uint32_t *pSurfaceFormatCount, |
| 5185 | VkSurfaceFormatKHR *pSurfaceFormats, |
| 5186 | VkResult result) { |
| 5187 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5188 | |
| 5189 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5190 | |
| 5191 | if (*pSurfaceFormatCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5192 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) |
| 5193 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
| 5194 | } |
| 5195 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5196 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
| 5197 | physical_device_state->surface_formats[i] = pSurfaceFormats[i]; |
| 5198 | } |
| 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 5203 | const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 5204 | uint32_t *pSurfaceFormatCount, |
| 5205 | VkSurfaceFormat2KHR *pSurfaceFormats, |
| 5206 | VkResult result) { |
| 5207 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5208 | |
| 5209 | auto physicalDeviceState = GetPhysicalDeviceState(physicalDevice); |
| 5210 | if (*pSurfaceFormatCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5211 | if (*pSurfaceFormatCount > physicalDeviceState->surface_formats.size()) |
| 5212 | physicalDeviceState->surface_formats.resize(*pSurfaceFormatCount); |
| 5213 | } |
| 5214 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5215 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
| 5216 | physicalDeviceState->surface_formats[i] = pSurfaceFormats[i].surfaceFormat; |
| 5217 | } |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 5222 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 5223 | BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 5224 | } |
| 5225 | |
| 5226 | void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) { |
| 5227 | EndCmdDebugUtilsLabel(report_data, commandBuffer); |
| 5228 | } |
| 5229 | |
| 5230 | void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 5231 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 5232 | InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 5233 | |
| 5234 | // Squirrel away an easily accessible copy. |
| 5235 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5236 | cb_state->debug_label = LoggingLabel(pLabelInfo); |
| 5237 | } |
| 5238 | |
| 5239 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState( |
| 5240 | uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHR *pPhysicalDeviceGroupProperties) { |
| 5241 | if (NULL != pPhysicalDeviceGroupProperties) { |
| 5242 | for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { |
| 5243 | for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) { |
| 5244 | VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j]; |
| 5245 | auto &phys_device_state = physical_device_map[cur_phys_dev]; |
| 5246 | phys_device_state.phys_device = cur_phys_dev; |
| 5247 | // Init actual features for each physical device |
| 5248 | DispatchGetPhysicalDeviceFeatures(cur_phys_dev, &phys_device_state.features2.features); |
| 5249 | } |
| 5250 | } |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups( |
| 5255 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHR *pPhysicalDeviceGroupProperties, |
| 5256 | VkResult result) { |
| 5257 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5258 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 5259 | } |
| 5260 | |
| 5261 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR( |
| 5262 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHR *pPhysicalDeviceGroupProperties, |
| 5263 | VkResult result) { |
| 5264 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5265 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 5266 | } |
| 5267 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5268 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice, |
| 5269 | uint32_t queueFamilyIndex, |
| 5270 | uint32_t *pCounterCount, |
| 5271 | VkPerformanceCounterKHR *pCounters) { |
| 5272 | if (NULL == pCounters) return; |
| 5273 | |
| 5274 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5275 | assert(physical_device_state); |
| 5276 | |
| 5277 | std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queueFamilyCounters(new QUEUE_FAMILY_PERF_COUNTERS()); |
| 5278 | queueFamilyCounters->counters.resize(*pCounterCount); |
| 5279 | for (uint32_t i = 0; i < *pCounterCount; i++) queueFamilyCounters->counters[i] = pCounters[i]; |
| 5280 | |
| 5281 | physical_device_state->perf_counters[queueFamilyIndex] = std::move(queueFamilyCounters); |
| 5282 | } |
| 5283 | |
| 5284 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( |
| 5285 | VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters, |
| 5286 | VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) { |
| 5287 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5288 | RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters); |
| 5289 | } |
| 5290 | |
| 5291 | void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo, |
| 5292 | VkResult result) { |
| 5293 | if (result == VK_SUCCESS) performance_lock_acquired = true; |
| 5294 | } |
| 5295 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5296 | void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) { |
| 5297 | performance_lock_acquired = false; |
| 5298 | for (auto &cmd_buffer : commandBufferMap) { |
| 5299 | cmd_buffer.second->performance_lock_released = true; |
| 5300 | } |
| 5301 | } |
| 5302 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5303 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device, |
| 5304 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5305 | const VkAllocationCallbacks *pAllocator) { |
| 5306 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5307 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5308 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5309 | desc_template_map.erase(descriptorUpdateTemplate); |
| 5310 | } |
| 5311 | |
| 5312 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device, |
| 5313 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5314 | const VkAllocationCallbacks *pAllocator) { |
| 5315 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5316 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5317 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5318 | desc_template_map.erase(descriptorUpdateTemplate); |
| 5319 | } |
| 5320 | |
| 5321 | void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, |
| 5322 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate) { |
| 5323 | safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5324 | auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5325 | desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state); |
| 5326 | } |
| 5327 | |
| 5328 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate( |
| 5329 | VkDevice device, const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 5330 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate, VkResult result) { |
| 5331 | if (VK_SUCCESS != result) return; |
| 5332 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 5333 | } |
| 5334 | |
| 5335 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR( |
| 5336 | VkDevice device, const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 5337 | VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate, VkResult result) { |
| 5338 | if (VK_SUCCESS != result) return; |
| 5339 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 5340 | } |
| 5341 | |
| 5342 | void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet, |
| 5343 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5344 | const void *pData) { |
| 5345 | auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate); |
| 5346 | if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) { |
| 5347 | assert(0); |
| 5348 | } else { |
| 5349 | const TEMPLATE_STATE *template_state = template_map_entry->second.get(); |
| 5350 | // TODO: Record template push descriptor updates |
| 5351 | if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) { |
| 5352 | PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData); |
| 5353 | } |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, |
| 5358 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 5359 | const void *pData) { |
| 5360 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 5361 | } |
| 5362 | |
| 5363 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet, |
| 5364 | VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, |
| 5365 | const void *pData) { |
| 5366 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 5367 | } |
| 5368 | |
| 5369 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR( |
| 5370 | VkCommandBuffer commandBuffer, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, VkPipelineLayout layout, uint32_t set, |
| 5371 | const void *pData) { |
| 5372 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5373 | |
| 5374 | const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 5375 | if (template_state) { |
| 5376 | auto layout_data = GetPipelineLayout(layout); |
| 5377 | auto dsl = GetDslFromPipelineLayout(layout_data, set); |
| 5378 | const auto &template_ci = template_state->create_info; |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 5379 | if (dsl && !dsl->destroyed) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5380 | // Decode the template into a set of write updates |
| 5381 | cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData, |
| 5382 | dsl->GetDescriptorSetLayout()); |
| 5383 | RecordCmdPushDescriptorSetState(cb_state, template_ci.pipelineBindPoint, layout, set, |
| 5384 | static_cast<uint32_t>(decoded_template.desc_writes.size()), |
| 5385 | decoded_template.desc_writes.data()); |
| 5386 | } |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice, |
| 5391 | uint32_t *pPropertyCount, void *pProperties) { |
| 5392 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 5393 | if (*pPropertyCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5394 | physical_device_state->display_plane_property_count = *pPropertyCount; |
| 5395 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 5396 | if (*pPropertyCount || pProperties) { |
| 5397 | physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 5402 | uint32_t *pPropertyCount, |
| 5403 | VkDisplayPlanePropertiesKHR *pProperties, |
| 5404 | VkResult result) { |
| 5405 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5406 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 5407 | } |
| 5408 | |
| 5409 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice, |
| 5410 | uint32_t *pPropertyCount, |
| 5411 | VkDisplayPlaneProperties2KHR *pProperties, |
| 5412 | VkResult result) { |
| 5413 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 5414 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 5415 | } |
| 5416 | |
| 5417 | void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5418 | uint32_t query, VkQueryControlFlags flags, uint32_t index) { |
| 5419 | QueryObject query_obj = {queryPool, query, index}; |
| 5420 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5421 | RecordCmdBeginQuery(cb_state, query_obj); |
| 5422 | } |
| 5423 | |
| 5424 | void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 5425 | uint32_t query, uint32_t index) { |
| 5426 | QueryObject query_obj = {queryPool, query, index}; |
| 5427 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5428 | RecordCmdEndQuery(cb_state, query_obj); |
| 5429 | } |
| 5430 | |
| 5431 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info, |
| 5432 | VkSamplerYcbcrConversion ycbcr_conversion) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5433 | auto ycbcr_state = std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(); |
| 5434 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5435 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5436 | RecordCreateSamplerYcbcrConversionANDROID(create_info, ycbcr_conversion, ycbcr_state.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5437 | } |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5438 | |
| 5439 | const VkFormat conversion_format = create_info->format; |
| 5440 | |
| 5441 | if (conversion_format != VK_FORMAT_UNDEFINED) { |
| 5442 | // If format is VK_FORMAT_UNDEFINED, will be set by external AHB features |
| 5443 | ycbcr_state->format_features = GetPotentialFormatFeatures(conversion_format); |
| 5444 | } |
| 5445 | |
| 5446 | ycbcr_state->chromaFilter = create_info->chromaFilter; |
| 5447 | ycbcr_state->format = conversion_format; |
| 5448 | samplerYcbcrConversionMap[ycbcr_conversion] = std::move(ycbcr_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device, |
| 5452 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 5453 | const VkAllocationCallbacks *pAllocator, |
| 5454 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 5455 | VkResult result) { |
| 5456 | if (VK_SUCCESS != result) return; |
| 5457 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 5458 | } |
| 5459 | |
| 5460 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device, |
| 5461 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 5462 | const VkAllocationCallbacks *pAllocator, |
| 5463 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 5464 | VkResult result) { |
| 5465 | if (VK_SUCCESS != result) return; |
| 5466 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 5467 | } |
| 5468 | |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5469 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) { |
| 5470 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 5471 | RecordDestroySamplerYcbcrConversionANDROID(ycbcr_conversion); |
| 5472 | } |
| 5473 | |
| 5474 | auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion); |
| 5475 | ycbcr_state->destroyed = true; |
| 5476 | samplerYcbcrConversionMap.erase(ycbcr_conversion); |
| 5477 | } |
| 5478 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5479 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, |
| 5480 | const VkAllocationCallbacks *pAllocator) { |
| 5481 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5482 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device, |
| 5486 | VkSamplerYcbcrConversion ycbcrConversion, |
| 5487 | const VkAllocationCallbacks *pAllocator) { |
| 5488 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 5489 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5490 | } |
| 5491 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5492 | void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 5493 | uint32_t queryCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5494 | // Do nothing if the feature is not enabled. |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 5495 | if (!enabled_features.core12.hostQueryReset) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5496 | |
| 5497 | // Do nothing if the query pool has been destroyed. |
| 5498 | auto query_pool_state = GetQueryPoolState(queryPool); |
| 5499 | if (!query_pool_state) return; |
| 5500 | |
| 5501 | // Reset the state of existing entries. |
| 5502 | QueryObject query_obj{queryPool, 0}; |
| 5503 | const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery); |
| 5504 | for (uint32_t i = 0; i < max_query_count; ++i) { |
| 5505 | query_obj.query = firstQuery + i; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 5506 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5507 | if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
| 5508 | for (uint32_t passIndex = 0; passIndex < query_pool_state->n_performance_passes; passIndex++) { |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 5509 | query_obj.perf_pass = passIndex; |
| 5510 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 5511 | } |
| 5512 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5513 | } |
| 5514 | } |
| 5515 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5516 | void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 5517 | uint32_t queryCount) { |
| 5518 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 5519 | } |
| 5520 | |
| 5521 | void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 5522 | uint32_t queryCount) { |
| 5523 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 5524 | } |
| 5525 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5526 | void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet, |
| 5527 | const TEMPLATE_STATE *template_state, const void *pData) { |
| 5528 | // Translate the templated update into a normal update for validation... |
| 5529 | cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData); |
| 5530 | cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()), |
| 5531 | decoded_update.desc_writes.data(), 0, NULL); |
| 5532 | } |
| 5533 | |
| 5534 | // Update the common AllocateDescriptorSetsData |
| 5535 | void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 5536 | cvdescriptorset::AllocateDescriptorSetsData *ds_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5537 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 5538 | auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5539 | if (layout) { |
| 5540 | ds_data->layout_nodes[i] = layout; |
| 5541 | // Count total descriptors required per type |
| 5542 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 5543 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
| 5544 | uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType); |
| 5545 | ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount; |
| 5546 | } |
| 5547 | } |
| 5548 | // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call |
| 5549 | } |
| 5550 | } |
| 5551 | |
| 5552 | // Decrement allocated sets from the pool and insert new sets into set_map |
| 5553 | void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 5554 | const VkDescriptorSet *descriptor_sets, |
| 5555 | const cvdescriptorset::AllocateDescriptorSetsData *ds_data) { |
| 5556 | auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get(); |
| 5557 | // Account for sets and individual descriptors allocated from pool |
| 5558 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
| 5559 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
| 5560 | pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first); |
| 5561 | } |
| 5562 | |
| 5563 | const auto *variable_count_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext); |
| 5564 | bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount; |
| 5565 | |
| 5566 | // Create tracking object for each descriptor set; insert into global map and the pool's set. |
| 5567 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 5568 | uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0; |
| 5569 | |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 5570 | 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] | 5571 | variable_count, this); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5572 | pool_state->sets.insert(new_ds.get()); |
| 5573 | new_ds->in_use.store(0); |
| 5574 | setMap[descriptor_sets[i]] = std::move(new_ds); |
| 5575 | } |
| 5576 | } |
| 5577 | |
| 5578 | // 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] | 5579 | void ValidationStateTracker::UpdateStateCmdDrawDispatchType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5580 | VkPipelineBindPoint bind_point, const char *function) { |
| 5581 | UpdateDrawState(cb_state, cmd_type, bind_point, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5582 | cb_state->hasDispatchCmd = true; |
| 5583 | } |
| 5584 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5585 | // Generic function to handle state update for all CmdDraw* type functions |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5586 | void ValidationStateTracker::UpdateStateCmdDrawType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, VkPipelineBindPoint bind_point, |
| 5587 | const char *function) { |
| 5588 | UpdateStateCmdDrawDispatchType(cb_state, cmd_type, bind_point, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5589 | cb_state->hasDrawCmd = true; |
| 5590 | } |
| 5591 | |
| 5592 | void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 5593 | uint32_t firstVertex, uint32_t firstInstance) { |
| 5594 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5595 | UpdateStateCmdDrawType(cb_state, CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, |
| 5599 | uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, |
| 5600 | uint32_t firstInstance) { |
| 5601 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5602 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5606 | uint32_t count, uint32_t stride) { |
| 5607 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5608 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5609 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5610 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5611 | } |
| 5612 | |
| 5613 | void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5614 | VkDeviceSize offset, uint32_t count, uint32_t stride) { |
| 5615 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5616 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5617 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5618 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5619 | } |
| 5620 | |
| 5621 | void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
| 5622 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5623 | UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5627 | VkDeviceSize offset) { |
| 5628 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5629 | UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5630 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5631 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5632 | } |
| 5633 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5634 | void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5635 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5636 | uint32_t stride, const char *function) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5637 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5638 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5639 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5640 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5641 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5642 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 5643 | } |
| 5644 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5645 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5646 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5647 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5648 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5649 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5650 | "vkCmdDrawIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5654 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 5655 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5656 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5657 | "vkCmdDrawIndirectCount()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 5661 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5662 | uint32_t maxDrawCount, uint32_t stride, const char *function) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5663 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5664 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5665 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5666 | UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5667 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5668 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 5669 | } |
| 5670 | |
| 5671 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5672 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5673 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5674 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5675 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5676 | "vkCmdDrawIndexedIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5680 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5681 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5682 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5683 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 5684 | "vkCmdDrawIndexedIndirectCount()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, |
| 5688 | uint32_t firstTask) { |
| 5689 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5690 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMeshTasksNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5694 | VkDeviceSize offset, uint32_t drawCount, uint32_t stride) { |
| 5695 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5696 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5697 | "vkCmdDrawMeshTasksIndirectNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5698 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5699 | if (buffer_state) { |
| 5700 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5701 | } |
| 5702 | } |
| 5703 | |
| 5704 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 5705 | VkDeviceSize offset, VkBuffer countBuffer, |
| 5706 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 5707 | uint32_t stride) { |
| 5708 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5709 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 5710 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 5711 | UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5712 | "vkCmdDrawMeshTasksIndirectCountNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5713 | if (buffer_state) { |
| 5714 | AddCommandBufferBindingBuffer(cb_state, buffer_state); |
| 5715 | } |
| 5716 | if (count_buffer_state) { |
| 5717 | AddCommandBufferBindingBuffer(cb_state, count_buffer_state); |
| 5718 | } |
| 5719 | } |
| 5720 | |
| 5721 | void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 5722 | const VkAllocationCallbacks *pAllocator, |
| 5723 | VkShaderModule *pShaderModule, VkResult result, |
| 5724 | void *csm_state_data) { |
| 5725 | if (VK_SUCCESS != result) return; |
| 5726 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
| 5727 | |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 5728 | 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] | 5729 | bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 5730 | auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment, |
| 5731 | csm_state->unique_shader_id) |
| 5732 | : std::make_shared<SHADER_MODULE_STATE>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5733 | shaderModuleMap[*pShaderModule] = std::move(new_shader_module); |
| 5734 | } |
| 5735 | |
| 5736 | void ValidationStateTracker::RecordPipelineShaderStage(VkPipelineShaderStageCreateInfo const *pStage, PIPELINE_STATE *pipeline, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 5737 | PIPELINE_STATE::StageState *stage_state) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5738 | // Validation shouldn't rely on anything in stage state being valid if the spirv isn't |
| 5739 | auto module = GetShaderModuleState(pStage->module); |
| 5740 | if (!module->has_valid_spirv) return; |
| 5741 | |
| 5742 | // Validation shouldn't rely on anything in stage state being valid if the entrypoint isn't present |
| 5743 | auto entrypoint = FindEntrypoint(module, pStage->pName, pStage->stage); |
| 5744 | if (entrypoint == module->end()) return; |
| 5745 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 5746 | stage_state->stage_flag = pStage->stage; |
| 5747 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5748 | // Mark accessible ids |
| 5749 | stage_state->accessible_ids = MarkAccessibleIds(module, entrypoint); |
| 5750 | ProcessExecutionModes(module, entrypoint, pipeline); |
| 5751 | |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 5752 | stage_state->descriptor_uses = CollectInterfaceByDescriptorSlot( |
| 5753 | 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] | 5754 | // Capture descriptor uses for the pipeline |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 5755 | for (const auto &use : stage_state->descriptor_uses) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5756 | // While validating shaders capture which slots are used by the pipeline |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 5757 | const uint32_t slot = use.first.first; |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 5758 | auto &reqs = pipeline->active_slots[slot][use.first.second].reqs; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5759 | reqs = descriptor_req(reqs | DescriptorTypeToReqs(module, use.second.type_id)); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 5760 | 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] | 5761 | 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] | 5762 | 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] | 5763 | |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 5764 | pipeline->max_active_slot = std::max(pipeline->max_active_slot, slot); |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 5765 | if (use.second.samplers_used_by_image.size()) { |
| 5766 | pipeline->active_slots[slot][use.first.second].samplers_used_by_image[stage_state->stage_flag] = |
| 5767 | &use.second.samplers_used_by_image; |
| 5768 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5769 | } |
locke-lunarg | 7848683 | 2020-09-09 19:39:42 -0600 | [diff] [blame] | 5770 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 5771 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
| 5772 | pipeline->fragmentShader_writable_output_location_list = CollectWritableOutputLocationinFS(*module, *pStage); |
| 5773 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | void ValidationStateTracker::ResetCommandBufferPushConstantDataIfIncompatible(CMD_BUFFER_STATE *cb_state, VkPipelineLayout layout) { |
| 5777 | if (cb_state == nullptr) { |
| 5778 | return; |
| 5779 | } |
| 5780 | |
| 5781 | const PIPELINE_LAYOUT_STATE *pipeline_layout_state = GetPipelineLayout(layout); |
| 5782 | if (pipeline_layout_state == nullptr) { |
| 5783 | return; |
| 5784 | } |
| 5785 | |
| 5786 | if (cb_state->push_constant_data_ranges != pipeline_layout_state->push_constant_ranges) { |
| 5787 | cb_state->push_constant_data_ranges = pipeline_layout_state->push_constant_ranges; |
| 5788 | cb_state->push_constant_data.clear(); |
| 5789 | uint32_t size_needed = 0; |
| 5790 | for (auto push_constant_range : *cb_state->push_constant_data_ranges) { |
| 5791 | size_needed = std::max(size_needed, (push_constant_range.offset + push_constant_range.size)); |
| 5792 | } |
| 5793 | cb_state->push_constant_data.resize(size_needed, 0); |
| 5794 | } |
| 5795 | } |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 5796 | |
| 5797 | void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 5798 | uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages, |
| 5799 | VkResult result) { |
| 5800 | if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return; |
| 5801 | auto swapchain_state = GetSwapchainState(swapchain); |
| 5802 | |
| 5803 | if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount); |
| 5804 | |
| 5805 | if (pSwapchainImages) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 5806 | for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) { |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 5807 | 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] | 5808 | |
| 5809 | // Add imageMap entries for each swapchain image |
| 5810 | VkImageCreateInfo image_ci; |
| 5811 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Mark Lobodzinski | d3ec86f | 2020-03-18 11:23:04 -0600 | [diff] [blame] | 5812 | image_ci.pNext = nullptr; // to be set later |
| 5813 | image_ci.flags = 0; // to be updated below |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 5814 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 5815 | image_ci.format = swapchain_state->createInfo.imageFormat; |
| 5816 | image_ci.extent.width = swapchain_state->createInfo.imageExtent.width; |
| 5817 | image_ci.extent.height = swapchain_state->createInfo.imageExtent.height; |
| 5818 | image_ci.extent.depth = 1; |
| 5819 | image_ci.mipLevels = 1; |
| 5820 | image_ci.arrayLayers = swapchain_state->createInfo.imageArrayLayers; |
| 5821 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 5822 | image_ci.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 5823 | image_ci.usage = swapchain_state->createInfo.imageUsage; |
| 5824 | image_ci.sharingMode = swapchain_state->createInfo.imageSharingMode; |
| 5825 | image_ci.queueFamilyIndexCount = swapchain_state->createInfo.queueFamilyIndexCount; |
| 5826 | image_ci.pQueueFamilyIndices = swapchain_state->createInfo.pQueueFamilyIndices; |
| 5827 | image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 5828 | |
| 5829 | image_ci.pNext = lvl_find_in_chain<VkImageFormatListCreateInfoKHR>(swapchain_state->createInfo.pNext); |
| 5830 | |
| 5831 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR) |
| 5832 | image_ci.flags |= VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT; |
| 5833 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR) |
| 5834 | image_ci.flags |= VK_IMAGE_CREATE_PROTECTED_BIT; |
| 5835 | if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) |
| 5836 | image_ci.flags |= (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR); |
| 5837 | |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 5838 | 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] | 5839 | auto &image_state = imageMap[pSwapchainImages[i]]; |
| 5840 | image_state->valid = false; |
| 5841 | image_state->create_from_swapchain = swapchain; |
| 5842 | image_state->bind_swapchain = swapchain; |
| 5843 | image_state->bind_swapchain_imageIndex = i; |
Tony-LunarG | e64e4fe | 2020-02-17 16:21:55 -0700 | [diff] [blame] | 5844 | image_state->is_swapchain_image = true; |
locke-lunarg | b358473 | 2019-10-28 20:18:36 -0600 | [diff] [blame] | 5845 | swapchain_state->images[i].image = pSwapchainImages[i]; |
| 5846 | swapchain_state->images[i].bound_images.emplace(pSwapchainImages[i]); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 5847 | |
| 5848 | AddImageStateProps(*image_state, device, physical_device); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | if (*pSwapchainImageCount) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 5853 | swapchain_state->get_swapchain_image_count = *pSwapchainImageCount; |
| 5854 | } |
| 5855 | } |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 5856 | |
| 5857 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureKHR( |
| 5858 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 5859 | const VkAccelerationStructureBuildOffsetInfoKHR *const *ppOffsetInfos) { |
| 5860 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5861 | if (cb_state == nullptr) { |
| 5862 | return; |
| 5863 | } |
| 5864 | for (uint32_t i = 0; i < infoCount; ++i) { |
| 5865 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureState(pInfos[i].dstAccelerationStructure); |
| 5866 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureState(pInfos[i].srcAccelerationStructure); |
| 5867 | if (dst_as_state != nullptr) { |
| 5868 | dst_as_state->built = true; |
| 5869 | dst_as_state->build_info_khr.initialize(pInfos); |
| 5870 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 5871 | } |
| 5872 | if (src_as_state != nullptr) { |
| 5873 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 5874 | } |
| 5875 | } |
| 5876 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 5877 | } |
| 5878 | |
| 5879 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, |
| 5880 | const VkCopyAccelerationStructureInfoKHR *pInfo) { |
| 5881 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5882 | if (cb_state) { |
| 5883 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureState(pInfo->src); |
| 5884 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureState(pInfo->dst); |
| 5885 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 5886 | dst_as_state->built = true; |
| 5887 | dst_as_state->build_info_khr = src_as_state->build_info_khr; |
| 5888 | AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state); |
| 5889 | AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state); |
| 5890 | } |
| 5891 | } |
| 5892 | } |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 5893 | |
| 5894 | void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) { |
| 5895 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5896 | cb_state->status |= CBSTATUS_CULL_MODE_SET; |
| 5897 | cb_state->static_status &= ~CBSTATUS_CULL_MODE_SET; |
| 5898 | } |
| 5899 | |
| 5900 | void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) { |
| 5901 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5902 | cb_state->status |= CBSTATUS_FRONT_FACE_SET; |
| 5903 | cb_state->static_status &= ~CBSTATUS_FRONT_FACE_SET; |
| 5904 | } |
| 5905 | |
| 5906 | void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer, |
| 5907 | VkPrimitiveTopology primitiveTopology) { |
| 5908 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5909 | cb_state->primitiveTopology = primitiveTopology; |
| 5910 | cb_state->status |= CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 5911 | cb_state->static_status &= ~CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 5912 | } |
| 5913 | |
| 5914 | void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount, |
| 5915 | const VkViewport *pViewports) { |
| 5916 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5917 | cb_state->viewportWithCountMask |= (1u << viewportCount) - 1u; |
| 5918 | cb_state->status |= CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 5919 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 5920 | } |
| 5921 | |
| 5922 | void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount, |
| 5923 | const VkRect2D *pScissors) { |
| 5924 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5925 | cb_state->scissorWithCountMask |= (1u << scissorCount) - 1u; |
| 5926 | cb_state->status |= CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 5927 | cb_state->static_status &= ~CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 5928 | } |
| 5929 | |
| 5930 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 5931 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 5932 | const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes, |
| 5933 | const VkDeviceSize *pStrides) { |
| 5934 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5935 | if (pStrides) { |
| 5936 | cb_state->status |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 5937 | cb_state->static_status &= ~CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 5938 | } |
| 5939 | |
| 5940 | uint32_t end = firstBinding + bindingCount; |
| 5941 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 5942 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 5943 | } |
| 5944 | |
| 5945 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 5946 | auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding]; |
| 5947 | vertex_buffer_binding.buffer = pBuffers[i]; |
| 5948 | vertex_buffer_binding.offset = pOffsets[i]; |
| 5949 | vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE; |
| 5950 | vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0; |
| 5951 | // Add binding for this vertex buffer to this commandbuffer |
| 5952 | if (pBuffers[i]) { |
| 5953 | AddCommandBufferBindingBuffer(cb_state, GetBufferState(pBuffers[i])); |
| 5954 | } |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) { |
| 5959 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5960 | cb_state->status |= CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 5961 | cb_state->static_status &= ~CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 5962 | } |
| 5963 | |
| 5964 | void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) { |
| 5965 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5966 | cb_state->status |= CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 5967 | cb_state->static_status &= ~CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 5968 | } |
| 5969 | |
| 5970 | void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) { |
| 5971 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5972 | cb_state->status |= CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 5973 | cb_state->static_status &= ~CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 5974 | } |
| 5975 | |
| 5976 | void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer, |
| 5977 | VkBool32 depthBoundsTestEnable) { |
| 5978 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5979 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 5980 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 5981 | } |
| 5982 | void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) { |
| 5983 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5984 | cb_state->status |= CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 5985 | cb_state->static_status &= ~CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 5986 | } |
| 5987 | |
| 5988 | void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 5989 | VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp, |
| 5990 | VkCompareOp compareOp) { |
| 5991 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5992 | cb_state->status |= CBSTATUS_STENCIL_OP_SET; |
| 5993 | cb_state->static_status &= ~CBSTATUS_STENCIL_OP_SET; |
| 5994 | } |