sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2021 Valve Corporation |
| 3 | * Copyright (c) 2015-2021 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2021 Google Inc. |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 5 | * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 20 | * Author: Dave Houlton <daveh@lunarg.com> |
| 21 | * Shannon McPherson <shannon@lunarg.com> |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 22 | * Author: Tobias Hector <tobias.hector@amd.com> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 23 | */ |
| 24 | |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 25 | #include <algorithm> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 26 | #include <cmath> |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 27 | |
| 28 | #include "vk_enum_string_helper.h" |
| 29 | #include "vk_format_utils.h" |
| 30 | #include "vk_layer_data.h" |
| 31 | #include "vk_layer_utils.h" |
| 32 | #include "vk_layer_logging.h" |
| 33 | #include "vk_typemap_helper.h" |
| 34 | |
| 35 | #include "chassis.h" |
| 36 | #include "state_tracker.h" |
| 37 | #include "shader_validation.h" |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 38 | #include "sync_utils.h" |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 39 | #include "cmd_buffer_state.h" |
| 40 | #include "render_pass_state.h" |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 41 | |
Mark Lobodzinski | b4ab6ac | 2020-04-02 13:12:06 -0600 | [diff] [blame] | 42 | void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) { |
| 43 | if (add_obj) { |
| 44 | instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type)); |
| 45 | // Call base class |
| 46 | ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj); |
| 47 | } |
| 48 | } |
| 49 | |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 50 | // NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS" |
| 51 | // attachments won't persist past the API entry point exit. |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 52 | static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin, |
| 53 | const FRAMEBUFFER_STATE &fb_state) { |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 54 | const VkImageView *attachments = fb_state.createInfo.pAttachments; |
| 55 | uint32_t count = fb_state.createInfo.attachmentCount; |
| 56 | if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 57 | const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 58 | if (framebuffer_attachments) { |
| 59 | attachments = framebuffer_attachments->pAttachments; |
| 60 | count = framebuffer_attachments->attachmentCount; |
| 61 | } |
| 62 | } |
| 63 | return std::make_pair(count, attachments); |
| 64 | } |
| 65 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 66 | template <typename ImageViewPointer, typename Get> |
| 67 | std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state, |
| 68 | const Get &get_fn) { |
| 69 | std::vector<ImageViewPointer> views; |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 70 | |
| 71 | const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state); |
| 72 | const auto attachment_count = count_attachment.first; |
| 73 | const auto *attachments = count_attachment.second; |
| 74 | views.resize(attachment_count, nullptr); |
| 75 | for (uint32_t i = 0; i < attachment_count; i++) { |
| 76 | if (attachments[i] != VK_NULL_HANDLE) { |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 77 | views[i] = get_fn(attachments[i]); |
John Zulauf | 2bc1fde | 2020-04-24 15:09:51 -0600 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | return views; |
| 81 | } |
| 82 | |
John Zulauf | 64ffe55 | 2021-02-06 10:25:07 -0700 | [diff] [blame] | 83 | std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetSharedAttachmentViews( |
| 84 | const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const { |
| 85 | auto get_fn = [this](VkImageView handle) { return this->GetShared<IMAGE_VIEW_STATE>(handle); }; |
| 86 | return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn); |
| 87 | } |
| 88 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 89 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 90 | // Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR |
| 91 | // This could also move into a seperate core_validation_android.cpp file... ? |
| 92 | |
Jeremy Gebben | f4fb2a0 | 2021-07-08 09:57:46 -0600 | [diff] [blame] | 93 | template <typename CreateInfo> |
| 94 | VkFormatFeatureFlags ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const { |
| 95 | VkFormatFeatureFlags format_features = 0; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 96 | const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 97 | if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) { |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 98 | // VUID 01894 will catch if not found in map |
| 99 | auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat); |
| 100 | if (it != ahb_ext_formats_map.end()) { |
Jeremy Gebben | f4fb2a0 | 2021-07-08 09:57:46 -0600 | [diff] [blame] | 101 | format_features = it->second; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 102 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 103 | } |
Jeremy Gebben | f4fb2a0 | 2021-07-08 09:57:46 -0600 | [diff] [blame] | 104 | return format_features; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 105 | } |
| 106 | |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 107 | void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID( |
| 108 | VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) { |
| 109 | if (VK_SUCCESS != result) return; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 110 | auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 111 | if (ahb_format_props) { |
Jeremy Gebben | fc6f815 | 2021-03-18 16:58:55 -0600 | [diff] [blame] | 112 | ahb_ext_formats_map.emplace(ahb_format_props->externalFormat, ahb_format_props->formatFeatures); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 116 | #else |
| 117 | |
Jeremy Gebben | f4fb2a0 | 2021-07-08 09:57:46 -0600 | [diff] [blame] | 118 | template <typename CreateInfo> |
| 119 | VkFormatFeatureFlags ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const { |
| 120 | return 0; |
| 121 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 122 | |
| 123 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 124 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 125 | VkFormatFeatureFlags GetImageFormatFeatures(VkPhysicalDevice physical_device, VkDevice device, VkImage image, VkFormat format, |
| 126 | VkImageTiling tiling) { |
| 127 | VkFormatFeatureFlags format_features = 0; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 128 | // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features) |
| 129 | // if format is AHB external format then the features are already set |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 130 | if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { |
| 131 | VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, |
| 132 | nullptr}; |
| 133 | DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 134 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 135 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr}; |
| 136 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 137 | nullptr}; |
| 138 | format_properties_2.pNext = (void *)&drm_properties_list; |
| 139 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
| 140 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 141 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 142 | drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0]; |
| 143 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 144 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 145 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
| 146 | if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) { |
| 147 | format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
| 148 | break; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 149 | } |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 150 | } |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 151 | } else { |
| 152 | VkFormatProperties format_properties; |
| 153 | DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties); |
| 154 | format_features = |
| 155 | (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 156 | } |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 157 | return format_features; |
Petr Kraus | 44f1c48 | 2020-04-25 20:09:25 +0200 | [diff] [blame] | 158 | } |
| 159 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 160 | void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 161 | const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) { |
| 162 | if (VK_SUCCESS != result) return; |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 163 | VkFormatFeatureFlags format_features = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 164 | if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 165 | format_features = GetExternalFormatFeaturesANDROID(pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 166 | } |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 167 | if (format_features == 0) { |
| 168 | format_features = GetImageFormatFeatures(physical_device, device, *pImage, pCreateInfo->format, pCreateInfo->tiling); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 169 | } |
| 170 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 171 | auto is_node = std::make_shared<IMAGE_STATE>(device, *pImage, pCreateInfo, format_features); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 172 | // Record the memory requirements in case they won't be queried |
sfricke-samsung | 013f1ef | 2020-05-14 22:56:20 -0700 | [diff] [blame] | 173 | // External AHB memory can't be queried until after memory is bound |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 174 | if (is_node->IsExternalAHB() == false) { |
sfricke-samsung | 71bc657 | 2020-04-29 15:49:43 -0700 | [diff] [blame] | 175 | if (is_node->disjoint == false) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 176 | DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements[0]); |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 177 | } else { |
| 178 | uint32_t plane_count = FormatPlaneCount(pCreateInfo->format); |
Jeremy Gebben | 0c09bc9 | 2021-08-11 13:58:16 -0600 | [diff] [blame] | 179 | static const std::array<VkImageAspectFlagBits, 3> aspects{VK_IMAGE_ASPECT_PLANE_0_BIT, VK_IMAGE_ASPECT_PLANE_1_BIT, |
| 180 | VK_IMAGE_ASPECT_PLANE_2_BIT}; |
| 181 | assert(plane_count <= aspects.size()); |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 182 | VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr}; |
Jeremy Gebben | 0c09bc9 | 2021-08-11 13:58:16 -0600 | [diff] [blame] | 183 | VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, &image_plane_req, |
| 184 | *pImage}; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 185 | |
Jeremy Gebben | 0c09bc9 | 2021-08-11 13:58:16 -0600 | [diff] [blame] | 186 | for (uint32_t i = 0; i < plane_count; i++) { |
| 187 | VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr}; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 188 | |
Jeremy Gebben | 0c09bc9 | 2021-08-11 13:58:16 -0600 | [diff] [blame] | 189 | image_plane_req.planeAspect = aspects[i]; |
| 190 | |
| 191 | if (device_extensions.vk_khr_get_memory_requirements2) { |
| 192 | DispatchGetImageMemoryRequirements2KHR(device, &mem_req_info2, &mem_reqs2); |
| 193 | } else { |
| 194 | DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2); |
| 195 | } |
| 196 | is_node->requirements[i] = mem_reqs2.memoryRequirements; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 199 | } |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 200 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 201 | imageMap[*pImage] = std::move(is_node); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
| 205 | if (!image) return; |
| 206 | IMAGE_STATE *image_state = GetImageState(image); |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 207 | if (!image_state) return; |
| 208 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 209 | image_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 210 | imageMap.erase(image); |
| 211 | } |
| 212 | |
| 213 | void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, |
| 214 | VkImageLayout imageLayout, const VkClearColorValue *pColor, |
| 215 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 216 | |
| 217 | if (disabled[command_buffer_state]) return; |
| 218 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 219 | auto cb_node = GetCBState(commandBuffer); |
| 220 | auto image_state = GetImageState(image); |
| 221 | if (cb_node && image_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 222 | cb_node->AddChild(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
| 226 | void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, |
| 227 | VkImageLayout imageLayout, |
| 228 | const VkClearDepthStencilValue *pDepthStencil, |
| 229 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 230 | if (disabled[command_buffer_state]) return; |
| 231 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 232 | auto cb_node = GetCBState(commandBuffer); |
| 233 | auto image_state = GetImageState(image); |
| 234 | if (cb_node && image_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 235 | cb_node->AddChild(image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 240 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 241 | uint32_t regionCount, const VkImageCopy *pRegions) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 242 | if (disabled[command_buffer_state]) return; |
| 243 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 244 | auto cb_node = GetCBState(commandBuffer); |
| 245 | auto src_image_state = GetImageState(srcImage); |
| 246 | auto dst_image_state = GetImageState(dstImage); |
| 247 | |
| 248 | // Update bindings between images and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 249 | cb_node->AddChild(src_image_state); |
| 250 | cb_node->AddChild(dst_image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 251 | } |
| 252 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 253 | void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer, |
| 254 | const VkCopyImageInfo2KHR *pCopyImageInfo) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 255 | if (disabled[command_buffer_state]) return; |
| 256 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 257 | auto cb_node = GetCBState(commandBuffer); |
| 258 | auto src_image_state = GetImageState(pCopyImageInfo->srcImage); |
| 259 | auto dst_image_state = GetImageState(pCopyImageInfo->dstImage); |
| 260 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 261 | cb_node->AddChild(src_image_state); |
| 262 | cb_node->AddChild(dst_image_state); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 263 | } |
| 264 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 265 | void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 266 | VkImageLayout srcImageLayout, VkImage dstImage, |
| 267 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 268 | const VkImageResolve *pRegions) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 269 | if (disabled[command_buffer_state]) return; |
| 270 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 271 | auto cb_node = GetCBState(commandBuffer); |
| 272 | auto src_image_state = GetImageState(srcImage); |
| 273 | auto dst_image_state = GetImageState(dstImage); |
| 274 | |
| 275 | // Update bindings between images and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 276 | cb_node->AddChild(src_image_state); |
| 277 | cb_node->AddChild(dst_image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 278 | } |
| 279 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 280 | void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer, |
| 281 | const VkResolveImageInfo2KHR *pResolveImageInfo) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 282 | if (disabled[command_buffer_state]) return; |
| 283 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 284 | auto cb_node = GetCBState(commandBuffer); |
| 285 | auto src_image_state = GetImageState(pResolveImageInfo->srcImage); |
| 286 | auto dst_image_state = GetImageState(pResolveImageInfo->dstImage); |
| 287 | |
| 288 | // Update bindings between images and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 289 | cb_node->AddChild(src_image_state); |
| 290 | cb_node->AddChild(dst_image_state); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 291 | } |
| 292 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 293 | void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 294 | VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 295 | uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 296 | if (disabled[command_buffer_state]) return; |
| 297 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 298 | auto cb_node = GetCBState(commandBuffer); |
| 299 | auto src_image_state = GetImageState(srcImage); |
| 300 | auto dst_image_state = GetImageState(dstImage); |
| 301 | |
| 302 | // Update bindings between images and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 303 | cb_node->AddChild(src_image_state); |
| 304 | cb_node->AddChild(dst_image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 305 | } |
| 306 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 307 | void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer, |
| 308 | const VkBlitImageInfo2KHR *pBlitImageInfo) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 309 | if (disabled[command_buffer_state]) return; |
| 310 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 311 | auto cb_node = GetCBState(commandBuffer); |
| 312 | auto src_image_state = GetImageState(pBlitImageInfo->srcImage); |
| 313 | auto dst_image_state = GetImageState(pBlitImageInfo->dstImage); |
| 314 | |
| 315 | // Update bindings between images and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 316 | cb_node->AddChild(src_image_state); |
| 317 | cb_node->AddChild(dst_image_state); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 318 | } |
| 319 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 320 | void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, |
| 321 | const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer, |
| 322 | VkResult result) { |
| 323 | if (result != VK_SUCCESS) return; |
Jeremy Gebben | f2912cd | 2021-07-07 07:57:39 -0600 | [diff] [blame] | 324 | |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 325 | auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 326 | |
James Rumble | 2f6e7bb | 2021-07-13 15:21:20 +0100 | [diff] [blame] | 327 | if (pCreateInfo) { |
| 328 | const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext); |
| 329 | if (opaque_capture_address) { |
| 330 | // address is used for GPU-AV and ray tracing buffer validation |
| 331 | buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress; |
| 332 | buffer_address_map_.emplace(opaque_capture_address->opaqueCaptureAddress, buffer_state.get()); |
| 333 | } |
| 334 | } |
| 335 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 336 | // Get a set of requirements in the case the app does not |
sfricke-samsung | ad90e72 | 2020-07-08 20:54:24 -0700 | [diff] [blame] | 337 | DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 338 | |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 339 | bufferMap.emplace(*pBuffer, std::move(buffer_state)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo, |
| 343 | const VkAllocationCallbacks *pAllocator, VkBufferView *pView, |
| 344 | VkResult result) { |
| 345 | if (result != VK_SUCCESS) return; |
Jeremy Gebben | f2912cd | 2021-07-07 07:57:39 -0600 | [diff] [blame] | 346 | |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 347 | auto buffer_state = GetBufferShared(pCreateInfo->buffer); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 348 | |
| 349 | VkFormatProperties format_properties; |
| 350 | DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 351 | |
Jeremy Gebben | f2912cd | 2021-07-07 07:57:39 -0600 | [diff] [blame] | 352 | bufferViewMap[*pView] = |
| 353 | std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, format_properties.bufferFeatures); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, |
| 357 | const VkAllocationCallbacks *pAllocator, VkImageView *pView, |
| 358 | VkResult result) { |
| 359 | if (result != VK_SUCCESS) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 360 | auto image_state = GetImageShared(pCreateInfo->image); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 361 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 362 | VkFormatFeatureFlags format_features = 0; |
| 363 | if (image_state->HasAHBFormat() == true) { |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 364 | // The ImageView uses same Image's format feature since they share same AHB |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 365 | format_features = image_state->format_features; |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 366 | } else { |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 367 | format_features = GetImageFormatFeatures(physical_device, device, image_state->image(), pCreateInfo->format, |
| 368 | image_state->createInfo.tiling); |
Spencer Fricke | 6bba8c7 | 2020-04-06 07:41:21 -0700 | [diff] [blame] | 369 | } |
| 370 | |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 371 | // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw. |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 372 | auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>(); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 373 | if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) { |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 374 | auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>(); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 375 | imageview_format_info.imageViewType = pCreateInfo->viewType; |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 376 | auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 377 | image_format_info.type = image_state->createInfo.imageType; |
| 378 | image_format_info.format = image_state->createInfo.format; |
| 379 | image_format_info.tiling = image_state->createInfo.tiling; |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 380 | auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext); |
| 381 | image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage; |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 382 | image_format_info.flags = image_state->createInfo.flags; |
| 383 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 384 | auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props); |
locke-lunarg | 9939d4b | 2020-10-26 20:11:08 -0600 | [diff] [blame] | 385 | |
| 386 | DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties); |
| 387 | } |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 388 | |
| 389 | imageViewMap[*pView] = |
| 390 | std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 394 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 395 | if (disabled[command_buffer_state]) return; |
| 396 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 397 | auto cb_node = GetCBState(commandBuffer); |
| 398 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 399 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 400 | |
| 401 | // Update bindings between buffers and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 402 | cb_node->AddChild(src_buffer_state); |
| 403 | cb_node->AddChild(dst_buffer_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 404 | } |
| 405 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 406 | void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, |
| 407 | const VkCopyBufferInfo2KHR *pCopyBufferInfos) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 408 | if (disabled[command_buffer_state]) return; |
| 409 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 410 | auto cb_node = GetCBState(commandBuffer); |
| 411 | auto src_buffer_state = GetBufferState(pCopyBufferInfos->srcBuffer); |
| 412 | auto dst_buffer_state = GetBufferState(pCopyBufferInfos->dstBuffer); |
| 413 | |
| 414 | // Update bindings between buffers and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 415 | cb_node->AddChild(src_buffer_state); |
| 416 | cb_node->AddChild(dst_buffer_state); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 417 | } |
| 418 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 419 | void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView, |
| 420 | const VkAllocationCallbacks *pAllocator) { |
| 421 | IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView); |
| 422 | if (!image_view_state) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 423 | |
| 424 | // Any bound cmd buffers are now invalid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 425 | image_view_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 426 | imageViewMap.erase(imageView); |
| 427 | } |
| 428 | |
| 429 | void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) { |
| 430 | if (!buffer) return; |
| 431 | auto buffer_state = GetBufferState(buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 432 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 433 | buffer_state->Destroy(); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 434 | bufferMap.erase(buffer_state->buffer()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, |
| 438 | const VkAllocationCallbacks *pAllocator) { |
| 439 | if (!bufferView) return; |
| 440 | auto buffer_view_state = GetBufferViewState(bufferView); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 441 | |
| 442 | // Any bound cmd buffers are now invalid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 443 | buffer_view_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 444 | bufferViewMap.erase(bufferView); |
| 445 | } |
| 446 | |
| 447 | void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 448 | VkDeviceSize size, uint32_t data) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 449 | if (disabled[command_buffer_state]) return; |
| 450 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 451 | auto cb_node = GetCBState(commandBuffer); |
| 452 | auto buffer_state = GetBufferState(dstBuffer); |
| 453 | // Update bindings between buffer and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 454 | cb_node->AddChild(buffer_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, |
| 458 | VkImageLayout srcImageLayout, VkBuffer dstBuffer, |
| 459 | uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 460 | if (disabled[command_buffer_state]) return; |
| 461 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 462 | auto cb_node = GetCBState(commandBuffer); |
| 463 | auto src_image_state = GetImageState(srcImage); |
| 464 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 465 | |
| 466 | // Update bindings between buffer/image and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 467 | cb_node->AddChild(src_image_state); |
| 468 | cb_node->AddChild(dst_buffer_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 469 | } |
| 470 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 471 | void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, |
| 472 | const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 473 | if (disabled[command_buffer_state]) return; |
| 474 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 475 | auto cb_node = GetCBState(commandBuffer); |
| 476 | auto src_image_state = GetImageState(pCopyImageToBufferInfo->srcImage); |
| 477 | auto dst_buffer_state = GetBufferState(pCopyImageToBufferInfo->dstBuffer); |
| 478 | |
| 479 | // Update bindings between buffer/image and cmd buffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 480 | cb_node->AddChild(src_image_state); |
| 481 | cb_node->AddChild(dst_buffer_state); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 482 | } |
| 483 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 484 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 485 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 486 | const VkBufferImageCopy *pRegions) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 487 | if (disabled[command_buffer_state]) return; |
| 488 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 489 | auto cb_node = GetCBState(commandBuffer); |
| 490 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 491 | auto dst_image_state = GetImageState(dstImage); |
| 492 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 493 | cb_node->AddChild(src_buffer_state); |
| 494 | cb_node->AddChild(dst_image_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 495 | } |
| 496 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 497 | void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, |
| 498 | const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 499 | |
| 500 | if (disabled[command_buffer_state]) return; |
| 501 | |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 502 | auto cb_node = GetCBState(commandBuffer); |
| 503 | auto src_buffer_state = GetBufferState(pCopyBufferToImageInfo->srcBuffer); |
| 504 | auto dst_image_state = GetImageState(pCopyBufferToImageInfo->dstImage); |
| 505 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 506 | cb_node->AddChild(src_buffer_state); |
| 507 | cb_node->AddChild(dst_image_state); |
Jeff Leger | 178b1e5 | 2020-10-05 12:22:23 -0400 | [diff] [blame] | 508 | } |
| 509 | |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 510 | QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) { |
| 511 | auto it = queueMap.find(queue); |
| 512 | if (it == queueMap.end()) { |
| 513 | return nullptr; |
| 514 | } |
| 515 | return &it->second; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 516 | } |
| 517 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 518 | const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const { |
| 519 | auto it = queueMap.find(queue); |
| 520 | if (it == queueMap.cend()) { |
| 521 | return nullptr; |
| 522 | } |
| 523 | return &it->second; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 524 | } |
| 525 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 526 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) const { |
| 527 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 528 | auto it = phys_dev_map->find(phys); |
| 529 | if (it == phys_dev_map->end()) { |
| 530 | return nullptr; |
| 531 | } |
| 532 | return &it->second; |
| 533 | } |
| 534 | |
| 535 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) { |
| 536 | auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map); |
| 537 | auto it = phys_dev_map->find(phys); |
| 538 | if (it == phys_dev_map->end()) { |
| 539 | return nullptr; |
| 540 | } |
| 541 | return &it->second; |
| 542 | } |
| 543 | |
| 544 | PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() { return physical_device_state; } |
| 545 | const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() const { return physical_device_state; } |
| 546 | |
| 547 | // Return ptr to memory binding for given handle of specified type |
| 548 | template <typename State, typename Result> |
| 549 | static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) { |
| 550 | switch (typed_handle.type) { |
| 551 | case kVulkanObjectTypeImage: |
| 552 | return state->GetImageState(typed_handle.Cast<VkImage>()); |
| 553 | case kVulkanObjectTypeBuffer: |
| 554 | return state->GetBufferState(typed_handle.Cast<VkBuffer>()); |
| 555 | case kVulkanObjectTypeAccelerationStructureNV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 556 | return state->GetAccelerationStructureStateNV(typed_handle.Cast<VkAccelerationStructureNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 557 | default: |
| 558 | break; |
| 559 | } |
| 560 | return nullptr; |
| 561 | } |
| 562 | |
| 563 | const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const { |
| 564 | return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle); |
| 565 | } |
| 566 | |
| 567 | BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) { |
| 568 | return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle); |
| 569 | } |
| 570 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 571 | // Remove set from setMap and delete the set |
| 572 | void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) { |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 573 | // Any bound cmd buffers are now invalid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 574 | descriptor_set->Destroy(); |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 575 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 576 | setMap.erase(descriptor_set->GetSet()); |
| 577 | } |
| 578 | |
| 579 | // Free all DS Pools including their Sets & related sub-structs |
| 580 | // NOTE : Calls to this function should be wrapped in mutex |
| 581 | void ValidationStateTracker::DeleteDescriptorSetPools() { |
| 582 | for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) { |
| 583 | // Remove this pools' sets from setMap and delete them |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 584 | for (auto *ds : ii->second->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 585 | FreeDescriptorSet(ds); |
| 586 | } |
| 587 | ii->second->sets.clear(); |
| 588 | ii = descriptorPoolMap.erase(ii); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | // For given object struct return a ptr of BASE_NODE type for its wrapping struct |
| 593 | BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) { |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 594 | if (object_struct.node) { |
| 595 | #ifdef _DEBUG |
| 596 | // assert that lookup would find the same object |
| 597 | VulkanTypedHandle other = object_struct; |
| 598 | other.node = nullptr; |
| 599 | assert(object_struct.node == GetStateStructPtrFromObject(other)); |
| 600 | #endif |
| 601 | return object_struct.node; |
| 602 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 603 | BASE_NODE *base_ptr = nullptr; |
| 604 | switch (object_struct.type) { |
| 605 | case kVulkanObjectTypeDescriptorSet: { |
| 606 | base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>()); |
| 607 | break; |
| 608 | } |
| 609 | case kVulkanObjectTypeSampler: { |
| 610 | base_ptr = GetSamplerState(object_struct.Cast<VkSampler>()); |
| 611 | break; |
| 612 | } |
| 613 | case kVulkanObjectTypeQueryPool: { |
| 614 | base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>()); |
| 615 | break; |
| 616 | } |
| 617 | case kVulkanObjectTypePipeline: { |
| 618 | base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>()); |
| 619 | break; |
| 620 | } |
| 621 | case kVulkanObjectTypeBuffer: { |
| 622 | base_ptr = GetBufferState(object_struct.Cast<VkBuffer>()); |
| 623 | break; |
| 624 | } |
| 625 | case kVulkanObjectTypeBufferView: { |
| 626 | base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>()); |
| 627 | break; |
| 628 | } |
| 629 | case kVulkanObjectTypeImage: { |
| 630 | base_ptr = GetImageState(object_struct.Cast<VkImage>()); |
| 631 | break; |
| 632 | } |
| 633 | case kVulkanObjectTypeImageView: { |
| 634 | base_ptr = GetImageViewState(object_struct.Cast<VkImageView>()); |
| 635 | break; |
| 636 | } |
| 637 | case kVulkanObjectTypeEvent: { |
| 638 | base_ptr = GetEventState(object_struct.Cast<VkEvent>()); |
| 639 | break; |
| 640 | } |
| 641 | case kVulkanObjectTypeDescriptorPool: { |
| 642 | base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>()); |
| 643 | break; |
| 644 | } |
| 645 | case kVulkanObjectTypeCommandPool: { |
| 646 | base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>()); |
| 647 | break; |
| 648 | } |
| 649 | case kVulkanObjectTypeFramebuffer: { |
| 650 | base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>()); |
| 651 | break; |
| 652 | } |
| 653 | case kVulkanObjectTypeRenderPass: { |
| 654 | base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>()); |
| 655 | break; |
| 656 | } |
| 657 | case kVulkanObjectTypeDeviceMemory: { |
| 658 | base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>()); |
| 659 | break; |
| 660 | } |
| 661 | case kVulkanObjectTypeAccelerationStructureNV: { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 662 | base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>()); |
| 663 | break; |
| 664 | } |
| 665 | case kVulkanObjectTypeAccelerationStructureKHR: { |
| 666 | base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 667 | break; |
| 668 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 669 | case kVulkanObjectTypeUnknown: |
| 670 | // This can happen if an element of the object_bindings vector has been |
| 671 | // zeroed out, after an object is destroyed. |
| 672 | break; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 673 | default: |
| 674 | // TODO : Any other objects to be handled here? |
| 675 | assert(0); |
| 676 | break; |
| 677 | } |
| 678 | return base_ptr; |
| 679 | } |
| 680 | |
sfricke-samsung | bf1a2ed | 2020-06-14 23:31:00 -0700 | [diff] [blame] | 681 | // Gets union of all features defined by Potential Format Features |
| 682 | // 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] | 683 | VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const { |
| 684 | VkFormatFeatureFlags format_features = 0; |
| 685 | |
| 686 | if (format != VK_FORMAT_UNDEFINED) { |
| 687 | VkFormatProperties format_properties; |
| 688 | DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties); |
| 689 | format_features |= format_properties.linearTilingFeatures; |
| 690 | format_features |= format_properties.optimalTilingFeatures; |
| 691 | if (device_extensions.vk_ext_image_drm_format_modifier) { |
| 692 | // VK_KHR_get_physical_device_properties2 is required in this case |
| 693 | VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2}; |
| 694 | VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT, |
| 695 | nullptr}; |
| 696 | format_properties_2.pNext = (void *)&drm_properties_list; |
Marc Alcala Prieto | 773871c | 2021-02-04 19:24:43 +0100 | [diff] [blame] | 697 | |
| 698 | // First call is to get the number of modifiers compatible with the queried format |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 699 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
Marc Alcala Prieto | 773871c | 2021-02-04 19:24:43 +0100 | [diff] [blame] | 700 | |
| 701 | std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties; |
| 702 | drm_properties.resize(drm_properties_list.drmFormatModifierCount); |
| 703 | drm_properties_list.pDrmFormatModifierProperties = drm_properties.data(); |
| 704 | |
| 705 | // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers |
| 706 | // compatible with the queried format |
| 707 | DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2); |
| 708 | |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 709 | for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) { |
| 710 | format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | return format_features; |
| 716 | } |
| 717 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 718 | void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 719 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, |
| 720 | VkResult result) { |
| 721 | if (VK_SUCCESS != result) return; |
| 722 | |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 723 | ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| 724 | ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type); |
| 725 | ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data); |
| 726 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 727 | const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures; |
| 728 | if (nullptr == enabled_features_found) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 729 | const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 730 | if (features2) { |
| 731 | enabled_features_found = &(features2->features); |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 732 | |
| 733 | const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(features2->pNext); |
| 734 | if (provoking_vertex_features) { |
| 735 | state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features; |
| 736 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 740 | if (nullptr == enabled_features_found) { |
| 741 | state_tracker->enabled_features.core = {}; |
| 742 | } else { |
| 743 | state_tracker->enabled_features.core = *enabled_features_found; |
| 744 | } |
| 745 | |
| 746 | // Make sure that queue_family_properties are obtained for this device's physical_device, even if the app has not |
| 747 | // previously set them through an explicit API call. |
| 748 | uint32_t count; |
| 749 | auto pd_state = GetPhysicalDeviceState(gpu); |
| 750 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr); |
| 751 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 752 | DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, &pd_state->queue_family_properties[0]); |
| 753 | // Save local link to this device's physical device state |
| 754 | state_tracker->physical_device_state = pd_state; |
| 755 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 756 | const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 757 | if (vulkan_12_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 758 | state_tracker->enabled_features.core12 = *vulkan_12_features; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 759 | } else { |
sfricke-samsung | 27c7072 | 2020-05-02 08:42:39 -0700 | [diff] [blame] | 760 | // Set Extension Feature Aliases to false as there is no struct to check |
| 761 | state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE; |
| 762 | state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE; |
| 763 | state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE; |
| 764 | state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE; |
| 765 | state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE; |
| 766 | state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE; |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 767 | state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE; |
sfricke-samsung | 27c7072 | 2020-05-02 08:42:39 -0700 | [diff] [blame] | 768 | |
| 769 | // 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] | 770 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 771 | const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 772 | if (eight_bit_storage_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 773 | state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess; |
| 774 | state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess = |
| 775 | eight_bit_storage_features->uniformAndStorageBuffer8BitAccess; |
| 776 | state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 779 | const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 780 | if (float16_int8_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 781 | state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16; |
| 782 | state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 785 | const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 786 | if (descriptor_indexing_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 787 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing = |
| 788 | descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing; |
| 789 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing = |
| 790 | descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing; |
| 791 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing = |
| 792 | descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing; |
| 793 | state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing = |
| 794 | descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing; |
| 795 | state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing = |
| 796 | descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing; |
| 797 | state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing = |
| 798 | descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing; |
| 799 | state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing = |
| 800 | descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing; |
| 801 | state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing = |
| 802 | descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing; |
| 803 | state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing = |
| 804 | descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing; |
| 805 | state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing = |
| 806 | descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing; |
| 807 | state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind = |
| 808 | descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind; |
| 809 | state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind = |
| 810 | descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind; |
| 811 | state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind = |
| 812 | descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind; |
| 813 | state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind = |
| 814 | descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind; |
| 815 | state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind = |
| 816 | descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind; |
| 817 | state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind = |
| 818 | descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind; |
| 819 | state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending = |
| 820 | descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending; |
| 821 | state_tracker->enabled_features.core12.descriptorBindingPartiallyBound = |
| 822 | descriptor_indexing_features->descriptorBindingPartiallyBound; |
| 823 | state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount = |
| 824 | descriptor_indexing_features->descriptorBindingVariableDescriptorCount; |
| 825 | state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 828 | const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 829 | if (scalar_block_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 830 | state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | const auto *imageless_framebuffer_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 834 | LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 835 | if (imageless_framebuffer_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 836 | state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | const auto *uniform_buffer_standard_layout_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 840 | LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 841 | if (uniform_buffer_standard_layout_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 842 | state_tracker->enabled_features.core12.uniformBufferStandardLayout = |
| 843 | uniform_buffer_standard_layout_features->uniformBufferStandardLayout; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | const auto *subgroup_extended_types_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 847 | LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 848 | if (subgroup_extended_types_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 849 | state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes = |
| 850 | subgroup_extended_types_features->shaderSubgroupExtendedTypes; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | const auto *separate_depth_stencil_layouts_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 854 | LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 855 | if (separate_depth_stencil_layouts_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 856 | state_tracker->enabled_features.core12.separateDepthStencilLayouts = |
| 857 | separate_depth_stencil_layouts_features->separateDepthStencilLayouts; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 860 | const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 861 | if (host_query_reset_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 862 | state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 865 | const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 866 | if (timeline_semaphore_features) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 867 | state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 870 | const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext); |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 871 | if (buffer_device_address) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 872 | state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress; |
| 873 | state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay = |
| 874 | buffer_device_address->bufferDeviceAddressCaptureReplay; |
| 875 | state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice = |
| 876 | buffer_device_address->bufferDeviceAddressMultiDevice; |
| 877 | } |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 878 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 879 | const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext); |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 880 | if (atomic_int64_features) { |
| 881 | state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics; |
| 882 | state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics; |
| 883 | } |
| 884 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 885 | const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext); |
sfricke-samsung | a4143ac | 2020-12-18 00:00:53 -0800 | [diff] [blame] | 886 | if (memory_model_features) { |
| 887 | state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel; |
| 888 | state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope = |
| 889 | memory_model_features->vulkanMemoryModelDeviceScope; |
| 890 | state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains = |
| 891 | memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains; |
| 892 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 895 | const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 896 | if (vulkan_11_features) { |
| 897 | state_tracker->enabled_features.core11 = *vulkan_11_features; |
| 898 | } else { |
| 899 | // These structs are only allowed in pNext chain if there is no kPhysicalDeviceVulkan11Features |
| 900 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 901 | const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 902 | if (sixteen_bit_storage_features) { |
| 903 | state_tracker->enabled_features.core11.storageBuffer16BitAccess = |
| 904 | sixteen_bit_storage_features->storageBuffer16BitAccess; |
| 905 | state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess = |
| 906 | sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess; |
| 907 | state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16; |
| 908 | state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16; |
| 909 | } |
| 910 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 911 | const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 912 | if (multiview_features) { |
| 913 | state_tracker->enabled_features.core11.multiview = multiview_features->multiview; |
| 914 | state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader; |
| 915 | state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader; |
| 916 | } |
| 917 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 918 | const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 919 | if (variable_pointers_features) { |
| 920 | state_tracker->enabled_features.core11.variablePointersStorageBuffer = |
| 921 | variable_pointers_features->variablePointersStorageBuffer; |
| 922 | state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers; |
| 923 | } |
| 924 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 925 | const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 926 | if (protected_memory_features) { |
| 927 | state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory; |
| 928 | } |
| 929 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 930 | const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 931 | if (ycbcr_conversion_features) { |
| 932 | state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion; |
| 933 | } |
| 934 | |
| 935 | const auto *shader_draw_parameters_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 936 | LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 937 | if (shader_draw_parameters_features) { |
| 938 | state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters; |
Tony-LunarG | b036c2f | 2019-12-05 14:38:25 -0700 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 942 | const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext); |
Tony-LunarG | ca4891a | 2020-08-10 15:46:46 -0600 | [diff] [blame] | 943 | if (device_group_ci) { |
| 944 | state_tracker->physical_device_count = device_group_ci->physicalDeviceCount; |
| 945 | state_tracker->device_group_create_info = *device_group_ci; |
| 946 | } else { |
| 947 | state_tracker->physical_device_count = 1; |
| 948 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 949 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 950 | const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 951 | if (exclusive_scissor_features) { |
| 952 | state_tracker->enabled_features.exclusive_scissor = *exclusive_scissor_features; |
| 953 | } |
| 954 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 955 | const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 956 | if (shading_rate_image_features) { |
| 957 | state_tracker->enabled_features.shading_rate_image = *shading_rate_image_features; |
| 958 | } |
| 959 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 960 | const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 961 | if (mesh_shader_features) { |
| 962 | state_tracker->enabled_features.mesh_shader = *mesh_shader_features; |
| 963 | } |
| 964 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 965 | const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 966 | if (inline_uniform_block_features) { |
| 967 | state_tracker->enabled_features.inline_uniform_block = *inline_uniform_block_features; |
| 968 | } |
| 969 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 970 | const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 971 | if (transform_feedback_features) { |
| 972 | state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features; |
| 973 | } |
| 974 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 975 | const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 976 | if (vtx_attrib_div_features) { |
| 977 | state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features; |
| 978 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 979 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 980 | const auto *buffer_device_address_ext = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext); |
Jeff Bolz | 4563f2a | 2019-12-10 13:30:30 -0600 | [diff] [blame] | 981 | if (buffer_device_address_ext) { |
Jeff Bolz | 33fc672 | 2020-03-31 12:58:16 -0500 | [diff] [blame] | 982 | state_tracker->enabled_features.buffer_device_address_ext = *buffer_device_address_ext; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 983 | } |
| 984 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 985 | const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 986 | if (cooperative_matrix_features) { |
| 987 | state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features; |
| 988 | } |
| 989 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 990 | const auto *compute_shader_derivatives_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 991 | LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 992 | if (compute_shader_derivatives_features) { |
| 993 | state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features; |
| 994 | } |
| 995 | |
| 996 | const auto *fragment_shader_barycentric_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 997 | LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 998 | if (fragment_shader_barycentric_features) { |
| 999 | state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features; |
| 1000 | } |
| 1001 | |
| 1002 | const auto *shader_image_footprint_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1003 | LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1004 | if (shader_image_footprint_features) { |
| 1005 | state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features; |
| 1006 | } |
| 1007 | |
| 1008 | const auto *fragment_shader_interlock_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1009 | LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1010 | if (fragment_shader_interlock_features) { |
| 1011 | state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features; |
| 1012 | } |
| 1013 | |
| 1014 | const auto *demote_to_helper_invocation_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1015 | LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1016 | if (demote_to_helper_invocation_features) { |
| 1017 | state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features; |
| 1018 | } |
| 1019 | |
| 1020 | const auto *texel_buffer_alignment_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1021 | LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1022 | if (texel_buffer_alignment_features) { |
| 1023 | state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features; |
| 1024 | } |
| 1025 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1026 | const auto *pipeline_exe_props_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1027 | LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1028 | if (pipeline_exe_props_features) { |
| 1029 | state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features; |
| 1030 | } |
| 1031 | |
Jeff Bolz | 82f854d | 2019-09-17 14:56:47 -0500 | [diff] [blame] | 1032 | const auto *dedicated_allocation_image_aliasing_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1033 | LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext); |
Jeff Bolz | 82f854d | 2019-09-17 14:56:47 -0500 | [diff] [blame] | 1034 | if (dedicated_allocation_image_aliasing_features) { |
| 1035 | state_tracker->enabled_features.dedicated_allocation_image_aliasing_features = |
| 1036 | *dedicated_allocation_image_aliasing_features; |
| 1037 | } |
| 1038 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1039 | const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1040 | if (performance_query_features) { |
| 1041 | state_tracker->enabled_features.performance_query_features = *performance_query_features; |
| 1042 | } |
| 1043 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1044 | const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext); |
Tobias Hector | 782bcde | 2019-11-28 16:19:42 +0000 | [diff] [blame] | 1045 | if (device_coherent_memory_features) { |
| 1046 | state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features; |
| 1047 | } |
| 1048 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1049 | const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | cead080 | 2020-01-30 22:20:10 -0800 | [diff] [blame] | 1050 | if (ycbcr_image_array_features) { |
| 1051 | state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features; |
| 1052 | } |
| 1053 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1054 | const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1055 | if (ray_query_features) { |
| 1056 | state_tracker->enabled_features.ray_query_features = *ray_query_features; |
| 1057 | } |
| 1058 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1059 | const auto *ray_tracing_pipeline_features = LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1060 | if (ray_tracing_pipeline_features) { |
| 1061 | state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features; |
| 1062 | } |
| 1063 | |
| 1064 | const auto *ray_tracing_acceleration_structure_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1065 | LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1066 | if (ray_tracing_acceleration_structure_features) { |
| 1067 | state_tracker->enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features; |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 1068 | } |
| 1069 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1070 | const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 1071 | if (robustness2_features) { |
| 1072 | state_tracker->enabled_features.robustness2_features = *robustness2_features; |
| 1073 | } |
| 1074 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1075 | const auto *fragment_density_map_features = LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext); |
janharaldfredriksen-arm | 3b79377 | 2020-05-12 18:55:53 +0200 | [diff] [blame] | 1076 | if (fragment_density_map_features) { |
| 1077 | state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features; |
| 1078 | } |
| 1079 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1080 | const auto *fragment_density_map_features2 = LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext); |
janharaldfredriksen-arm | 36e1757 | 2020-07-07 13:59:28 +0200 | [diff] [blame] | 1081 | if (fragment_density_map_features2) { |
| 1082 | state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2; |
| 1083 | } |
| 1084 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1085 | const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | 0c4a06f | 2020-06-27 01:24:32 -0700 | [diff] [blame] | 1086 | if (astc_decode_features) { |
| 1087 | state_tracker->enabled_features.astc_decode_features = *astc_decode_features; |
| 1088 | } |
| 1089 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1090 | const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext); |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 1091 | if (custom_border_color_features) { |
| 1092 | state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features; |
| 1093 | } |
| 1094 | |
sfricke-samsung | fd661d6 | 2020-05-16 00:57:27 -0700 | [diff] [blame] | 1095 | const auto *pipeline_creation_cache_control_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1096 | LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | fd661d6 | 2020-05-16 00:57:27 -0700 | [diff] [blame] | 1097 | if (pipeline_creation_cache_control_features) { |
| 1098 | state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features; |
| 1099 | } |
| 1100 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1101 | const auto *fragment_shading_rate_features = LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext); |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1102 | if (fragment_shading_rate_features) { |
| 1103 | state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features; |
| 1104 | } |
| 1105 | |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1106 | const auto *extended_dynamic_state_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1107 | LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 1108 | if (extended_dynamic_state_features) { |
| 1109 | state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features; |
| 1110 | } |
| 1111 | |
Vikram Kushwaha | a57b0c3 | 2021-04-19 12:21:46 -0700 | [diff] [blame] | 1112 | const auto *extended_dynamic_state2_features = |
| 1113 | LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext); |
| 1114 | if (extended_dynamic_state2_features) { |
| 1115 | state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features; |
| 1116 | } |
| 1117 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1118 | const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext); |
locke-lunarg | 3fa463a | 2020-10-23 16:39:04 -0600 | [diff] [blame] | 1119 | if (multiview_features) { |
| 1120 | state_tracker->enabled_features.multiview_features = *multiview_features; |
| 1121 | } |
| 1122 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1123 | const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext); |
Nathaniel Cesario | b3f2d70 | 2020-11-09 09:20:49 -0700 | [diff] [blame] | 1124 | if (portability_features) { |
| 1125 | state_tracker->enabled_features.portability_subset_features = *portability_features; |
| 1126 | } |
| 1127 | |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1128 | const auto *shader_integer_functions2_features = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1129 | LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1130 | if (shader_integer_functions2_features) { |
| 1131 | state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features; |
| 1132 | } |
| 1133 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1134 | const auto *shader_sm_builtins_feature = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1135 | if (shader_sm_builtins_feature) { |
| 1136 | state_tracker->enabled_features.shader_sm_builtins_feature = *shader_sm_builtins_feature; |
| 1137 | } |
| 1138 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1139 | const auto *shader_atomic_float_feature = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1140 | if (shader_atomic_float_feature) { |
| 1141 | state_tracker->enabled_features.shader_atomic_float_feature = *shader_atomic_float_feature; |
| 1142 | } |
| 1143 | |
| 1144 | const auto *shader_image_atomic_int64_feature = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1145 | LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 1146 | if (shader_image_atomic_int64_feature) { |
| 1147 | state_tracker->enabled_features.shader_image_atomic_int64_feature = *shader_image_atomic_int64_feature; |
| 1148 | } |
| 1149 | |
sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 1150 | const auto *shader_clock_feature = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext); |
| 1151 | if (shader_clock_feature) { |
| 1152 | state_tracker->enabled_features.shader_clock_feature = *shader_clock_feature; |
| 1153 | } |
| 1154 | |
Jeremy Gebben | 5f585ae | 2021-02-02 09:03:06 -0700 | [diff] [blame] | 1155 | const auto *conditional_rendering_features = |
| 1156 | LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext); |
| 1157 | if (conditional_rendering_features) { |
| 1158 | state_tracker->enabled_features.conditional_rendering = *conditional_rendering_features; |
| 1159 | } |
| 1160 | |
Shannon McPherson | db287d4 | 2021-02-02 15:27:32 -0700 | [diff] [blame] | 1161 | const auto *workgroup_memory_explicit_layout_features = |
| 1162 | LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext); |
| 1163 | if (workgroup_memory_explicit_layout_features) { |
| 1164 | state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features; |
| 1165 | } |
| 1166 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1167 | const auto *synchronization2_features = |
| 1168 | LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext); |
| 1169 | if (synchronization2_features) { |
| 1170 | state_tracker->enabled_features.synchronization2_features = *synchronization2_features; |
| 1171 | } |
| 1172 | |
Locke Lin | f387354 | 2021-04-26 11:25:10 -0600 | [diff] [blame] | 1173 | const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext); |
| 1174 | if (provoking_vertex_features) { |
| 1175 | state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features; |
| 1176 | } |
| 1177 | |
Piers Daniell | cb6d803 | 2021-04-19 18:51:26 -0600 | [diff] [blame] | 1178 | const auto *vertex_input_dynamic_state_features = |
| 1179 | LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext); |
| 1180 | if (vertex_input_dynamic_state_features) { |
| 1181 | state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features; |
| 1182 | } |
| 1183 | |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 1184 | const auto *inherited_viewport_scissor_features = |
| 1185 | LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext); |
| 1186 | if (inherited_viewport_scissor_features) { |
| 1187 | state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features; |
| 1188 | } |
| 1189 | |
Tony-LunarG | 4490de4 | 2021-06-21 15:49:19 -0600 | [diff] [blame] | 1190 | const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext); |
| 1191 | if (multi_draw_features) { |
| 1192 | state_tracker->enabled_features.multi_draw_features = *multi_draw_features; |
| 1193 | } |
| 1194 | |
ziga-lunarg | 29ba2b9 | 2021-07-20 21:51:45 +0200 | [diff] [blame] | 1195 | const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext); |
| 1196 | if (color_write_features) { |
| 1197 | state_tracker->enabled_features.color_write_features = *color_write_features; |
| 1198 | } |
| 1199 | |
Mike Schuchardt | b3870ea | 2021-07-20 18:56:51 -0700 | [diff] [blame] | 1200 | const auto *shader_atomic_float2_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext); |
| 1201 | if (shader_atomic_float2_features) { |
| 1202 | state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features; |
| 1203 | } |
| 1204 | |
Tony-LunarG | 6f887e5 | 2021-07-27 11:23:14 -0600 | [diff] [blame] | 1205 | const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext); |
| 1206 | if (present_id_features) { |
| 1207 | state_tracker->enabled_features.present_id_features = *present_id_features; |
| 1208 | } |
| 1209 | |
| 1210 | const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext); |
| 1211 | if (present_wait_features) { |
| 1212 | state_tracker->enabled_features.present_wait_features = *present_wait_features; |
| 1213 | } |
| 1214 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1215 | // Store physical device properties and physical device mem limits into CoreChecks structs |
| 1216 | DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props); |
| 1217 | DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1218 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 1219 | &state_tracker->phys_dev_props_core11); |
| 1220 | GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2, |
| 1221 | &state_tracker->phys_dev_props_core12); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1222 | |
| 1223 | const auto &dev_ext = state_tracker->device_extensions; |
| 1224 | auto *phys_dev_props = &state_tracker->phys_dev_ext_props; |
| 1225 | |
| 1226 | if (dev_ext.vk_khr_push_descriptor) { |
| 1227 | // Get the needed push_descriptor limits |
| 1228 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor_prop; |
| 1229 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &push_descriptor_prop); |
| 1230 | phys_dev_props->max_push_descriptors = push_descriptor_prop.maxPushDescriptors; |
| 1231 | } |
| 1232 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1233 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_ext_descriptor_indexing) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1234 | VkPhysicalDeviceDescriptorIndexingProperties descriptor_indexing_prop; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1235 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop); |
| 1236 | state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools = |
| 1237 | descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools; |
| 1238 | state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative = |
| 1239 | descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative; |
| 1240 | state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative = |
| 1241 | descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative; |
| 1242 | state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative = |
| 1243 | descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative; |
| 1244 | state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative = |
| 1245 | descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative; |
| 1246 | state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative = |
| 1247 | descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative; |
| 1248 | state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind = |
| 1249 | descriptor_indexing_prop.robustBufferAccessUpdateAfterBind; |
| 1250 | state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod; |
| 1251 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers = |
| 1252 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers; |
| 1253 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers = |
| 1254 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers; |
| 1255 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers = |
| 1256 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers; |
| 1257 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages = |
| 1258 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages; |
| 1259 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages = |
| 1260 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages; |
| 1261 | state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments = |
| 1262 | descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments; |
| 1263 | state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources = |
| 1264 | descriptor_indexing_prop.maxPerStageUpdateAfterBindResources; |
| 1265 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers = |
| 1266 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers; |
| 1267 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers = |
| 1268 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers; |
| 1269 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic = |
| 1270 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic; |
| 1271 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers = |
| 1272 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers; |
| 1273 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic = |
| 1274 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic; |
| 1275 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages = |
| 1276 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages; |
| 1277 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages = |
| 1278 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages; |
| 1279 | state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments = |
| 1280 | descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments; |
| 1281 | } |
| 1282 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1283 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props); |
| 1284 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props); |
| 1285 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props); |
| 1286 | 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] | 1287 | |
| 1288 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_depth_stencil_resolve) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1289 | VkPhysicalDeviceDepthStencilResolveProperties depth_stencil_resolve_props; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1290 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props); |
| 1291 | state_tracker->phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes; |
| 1292 | state_tracker->phys_dev_props_core12.supportedStencilResolveModes = |
| 1293 | depth_stencil_resolve_props.supportedStencilResolveModes; |
| 1294 | state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone; |
| 1295 | state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve; |
| 1296 | } |
| 1297 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1298 | 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] | 1299 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 1300 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR); |
| 1301 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1302 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props); |
| 1303 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props); |
Mike Schuchardt | c57de4a | 2021-07-20 17:26:32 -0700 | [diff] [blame] | 1304 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1305 | 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] | 1306 | 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] | 1307 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props); |
locke-lunarg | 3fa463a | 2020-10-23 16:39:04 -0600 | [diff] [blame] | 1308 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props); |
Nathaniel Cesario | 3291c91 | 2020-11-17 16:54:41 -0700 | [diff] [blame] | 1309 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props); |
Locke Lin | 016d848 | 2021-05-27 12:11:31 -0600 | [diff] [blame] | 1310 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props); |
Tony-LunarG | 4490de4 | 2021-06-21 15:49:19 -0600 | [diff] [blame] | 1311 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props); |
ziga-lunarg | 128904a | 2021-07-30 13:49:01 +0200 | [diff] [blame] | 1312 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props); |
ziga-lunarg | 8649281 | 2021-08-05 23:58:16 +0200 | [diff] [blame] | 1313 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1314 | |
| 1315 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_timeline_semaphore) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1316 | VkPhysicalDeviceTimelineSemaphoreProperties timeline_semaphore_props; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1317 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props); |
| 1318 | state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference = |
| 1319 | timeline_semaphore_props.maxTimelineSemaphoreValueDifference; |
| 1320 | } |
| 1321 | |
| 1322 | if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_shader_float_controls) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1323 | VkPhysicalDeviceFloatControlsProperties float_controls_props; |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1324 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props); |
| 1325 | state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence; |
| 1326 | state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence; |
| 1327 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 = |
| 1328 | float_controls_props.shaderSignedZeroInfNanPreserveFloat16; |
| 1329 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 = |
| 1330 | float_controls_props.shaderSignedZeroInfNanPreserveFloat32; |
| 1331 | state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 = |
| 1332 | float_controls_props.shaderSignedZeroInfNanPreserveFloat64; |
| 1333 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16; |
| 1334 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32; |
| 1335 | state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64; |
| 1336 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16; |
| 1337 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32; |
| 1338 | state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64; |
| 1339 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16; |
| 1340 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32; |
| 1341 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64; |
| 1342 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16; |
| 1343 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32; |
| 1344 | state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64; |
| 1345 | } |
Mark Lobodzinski | e4a2b7f | 2019-12-20 12:51:30 -0700 | [diff] [blame] | 1346 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1347 | if (state_tracker->device_extensions.vk_nv_cooperative_matrix) { |
| 1348 | // Get the needed cooperative_matrix properties |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 1349 | auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>(); |
| 1350 | auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1351 | instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2); |
| 1352 | state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props; |
| 1353 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1354 | uint32_t num_cooperative_matrix_properties = 0; |
| 1355 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL); |
| 1356 | state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties, |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 1357 | LvlInitStruct<VkCooperativeMatrixPropertiesNV>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1358 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1359 | instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1360 | state_tracker->cooperative_matrix_properties.data()); |
| 1361 | } |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1362 | 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] | 1363 | // Get the needed subgroup limits |
Locke Lin | 016d848 | 2021-05-27 12:11:31 -0600 | [diff] [blame] | 1364 | auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>(); |
Mark Lobodzinski | 6fe9e70 | 2020-12-30 15:36:39 -0700 | [diff] [blame] | 1365 | auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&subgroup_prop); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1366 | instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2); |
| 1367 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1368 | state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize; |
| 1369 | state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages; |
| 1370 | state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations; |
| 1371 | state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1372 | } |
| 1373 | |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1374 | GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props); |
| 1375 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1376 | // Store queue family data |
| 1377 | if (pCreateInfo->pQueueCreateInfos != nullptr) { |
| 1378 | for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) { |
sfricke-samsung | 590ae1e | 2020-04-25 01:18:05 -0700 | [diff] [blame] | 1379 | const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i]; |
sfricke-samsung | b585ec1 | 2021-05-06 03:10:13 -0700 | [diff] [blame] | 1380 | state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex); |
| 1381 | state_tracker->device_queue_info_list.push_back( |
| 1382 | {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount}); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 1388 | if (!device) return; |
| 1389 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1390 | // Reset all command buffers before destroying them, to unlink object_bindings. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1391 | for (auto &command_buffer : commandBufferMap) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 1392 | command_buffer.second->Reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1393 | } |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 1394 | pipelineMap.clear(); |
| 1395 | renderPassMap.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1396 | commandBufferMap.clear(); |
| 1397 | |
| 1398 | // This will also delete all sets in the pool & remove them from setMap |
| 1399 | DeleteDescriptorSetPools(); |
| 1400 | // All sets should be removed |
| 1401 | assert(setMap.empty()); |
| 1402 | descriptorSetLayoutMap.clear(); |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 1403 | // Because swapchains are associated with Surfaces, which are at instance level, |
| 1404 | // they need to be explicitly destroyed here to avoid continued references to |
| 1405 | // the device we're destroying. |
| 1406 | for (auto &entry : swapchainMap) { |
| 1407 | entry.second->Destroy(); |
| 1408 | } |
| 1409 | swapchainMap.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1410 | imageViewMap.clear(); |
| 1411 | imageMap.clear(); |
| 1412 | bufferViewMap.clear(); |
| 1413 | bufferMap.clear(); |
| 1414 | // Queues persist until device is destroyed |
| 1415 | queueMap.clear(); |
| 1416 | } |
| 1417 | |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1418 | void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) { |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1419 | layer_data::unordered_map<VkQueue, uint64_t> other_queue_seqs; |
| 1420 | layer_data::unordered_map<VkSemaphore, uint64_t> timeline_semaphore_counters; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1421 | |
| 1422 | // Roll this queue forward, one submission at a time. |
| 1423 | while (pQueue->seq < seq) { |
| 1424 | auto &submission = pQueue->submissions.front(); |
| 1425 | |
| 1426 | for (auto &wait : submission.waitSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1427 | auto semaphore_state = GetSemaphoreState(wait.semaphore); |
| 1428 | if (semaphore_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1429 | semaphore_state->EndUse(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1430 | } |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1431 | if (wait.type == VK_SEMAPHORE_TYPE_TIMELINE) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1432 | auto &last_counter = timeline_semaphore_counters[wait.semaphore]; |
| 1433 | last_counter = std::max(last_counter, wait.payload); |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 1434 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1435 | auto &last_seq = other_queue_seqs[wait.queue]; |
| 1436 | last_seq = std::max(last_seq, wait.seq); |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 1437 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1438 | } |
| 1439 | |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 1440 | for (auto &signal : submission.signalSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1441 | auto semaphore_state = GetSemaphoreState(signal.semaphore); |
| 1442 | if (semaphore_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1443 | semaphore_state->EndUse(); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1444 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_TIMELINE && semaphore_state->payload < signal.payload) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1445 | semaphore_state->payload = signal.payload; |
Juan A. Suarez Romero | 9cef885 | 2020-03-10 12:19:42 +0100 | [diff] [blame] | 1446 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | for (auto &semaphore : submission.externalSemaphores) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1451 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 1452 | if (semaphore_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1453 | semaphore_state->EndUse(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | for (auto cb : submission.cbs) { |
| 1458 | auto cb_node = GetCBState(cb); |
| 1459 | if (!cb_node) { |
| 1460 | continue; |
| 1461 | } |
| 1462 | // First perform decrement on general case bound objects |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1463 | for (auto event : cb_node->writeEventsBeforeWait) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1464 | auto event_node = eventMap.find(event); |
| 1465 | if (event_node != eventMap.end()) { |
John Zulauf | 4805732 | 2020-12-02 11:59:31 -0700 | [diff] [blame] | 1466 | event_node->second->write_in_use--; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1467 | } |
| 1468 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1469 | QueryMap local_query_to_state_map; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 1470 | VkQueryPool first_pool = VK_NULL_HANDLE; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 1471 | for (auto &function : cb_node->queryUpdates) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1472 | function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 1473 | } |
| 1474 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1475 | for (const auto &query_state_pair : local_query_to_state_map) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1476 | if (query_state_pair.second == QUERYSTATE_ENDED) { |
| 1477 | queryToStateMap[query_state_pair.first] = QUERYSTATE_AVAILABLE; |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1478 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1479 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1480 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) { |
| 1481 | cb_node->EndUse(); |
| 1482 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1483 | } |
| 1484 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1485 | auto fence_state = GetFenceState(submission.fence); |
| 1486 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
| 1487 | fence_state->state = FENCE_RETIRED; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | pQueue->submissions.pop_front(); |
| 1491 | pQueue->seq++; |
| 1492 | } |
| 1493 | |
| 1494 | // Roll other queues forward to the highest seq we saw a wait for |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1495 | for (const auto &qs : other_queue_seqs) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1496 | RetireWorkOnQueue(GetQueueState(qs.first), qs.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1497 | } |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1498 | for (const auto &sc : timeline_semaphore_counters) { |
Marshall Drew-Brook | 0384758 | 2020-11-06 15:10:45 -0800 | [diff] [blame] | 1499 | RetireTimelineSemaphore(sc.first, sc.second); |
| 1500 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | // Submit a fence to a queue, delimiting previous fences and previous untracked |
| 1504 | // work by it. |
| 1505 | static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) { |
| 1506 | pFence->state = FENCE_INFLIGHT; |
| 1507 | pFence->signaler.first = pQueue->queue; |
| 1508 | pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount; |
| 1509 | } |
| 1510 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1511 | uint64_t ValidationStateTracker::RecordSubmitFence(QUEUE_STATE *queue_state, VkFence fence, uint32_t submit_count) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1512 | auto fence_state = GetFenceState(fence); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1513 | uint64_t early_retire_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1514 | if (fence_state) { |
| 1515 | if (fence_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1516 | // Mark fence in use |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1517 | SubmitFence(queue_state, fence_state, std::max(1u, submit_count)); |
| 1518 | if (!submit_count) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1519 | // If no submissions, but just dropping a fence on the end of the queue, |
| 1520 | // record an empty submission with just the fence, so we can determine |
| 1521 | // its completion. |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1522 | CB_SUBMISSION submission; |
| 1523 | submission.fence = fence; |
| 1524 | queue_state->submissions.emplace_back(std::move(submission)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1525 | } |
| 1526 | } else { |
| 1527 | // Retire work up until this fence early, we will not see the wait that corresponds to this signal |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1528 | early_retire_seq = queue_state->seq + queue_state->submissions.size(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1529 | } |
| 1530 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1531 | return early_retire_seq; |
| 1532 | } |
| 1533 | |
| 1534 | void ValidationStateTracker::RecordSubmitCommandBuffer(CB_SUBMISSION &submission, VkCommandBuffer command_buffer) { |
| 1535 | auto cb_node = GetCBState(command_buffer); |
| 1536 | if (cb_node) { |
| 1537 | submission.cbs.push_back(command_buffer); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1538 | for (auto *secondary_cmd_buffer : cb_node->linkedCommandBuffers) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1539 | submission.cbs.push_back(secondary_cmd_buffer->commandBuffer()); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 1540 | secondary_cmd_buffer->IncrementResources(); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1541 | } |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 1542 | cb_node->IncrementResources(); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1543 | // increment use count for all bound objects including secondary cbs |
| 1544 | cb_node->BeginUse(); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1545 | |
| 1546 | VkQueryPool first_pool = VK_NULL_HANDLE; |
| 1547 | EventToStageMap local_event_to_stage_map; |
| 1548 | QueryMap local_query_to_state_map; |
| 1549 | for (auto &function : cb_node->queryUpdates) { |
| 1550 | function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map); |
| 1551 | } |
| 1552 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1553 | for (const auto &query_state_pair : local_query_to_state_map) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1554 | queryToStateMap[query_state_pair.first] = query_state_pair.second; |
| 1555 | } |
| 1556 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1557 | for (const auto &function : cb_node->eventUpdates) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1558 | function(nullptr, /*do_validate*/ false, &local_event_to_stage_map); |
| 1559 | } |
| 1560 | |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1561 | for (const auto &eventStagePair : local_event_to_stage_map) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1562 | eventMap[eventStagePair.first]->stageMask = eventStagePair.second; |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | void ValidationStateTracker::RecordSubmitWaitSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore, |
| 1568 | uint64_t value, uint64_t next_seq) { |
| 1569 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 1570 | if (semaphore_state) { |
| 1571 | if (semaphore_state->scope == kSyncScopeInternal) { |
| 1572 | SEMAPHORE_WAIT wait; |
| 1573 | wait.semaphore = semaphore; |
| 1574 | wait.type = semaphore_state->type; |
| 1575 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) { |
| 1576 | if (semaphore_state->signaler.first != VK_NULL_HANDLE) { |
| 1577 | wait.queue = semaphore_state->signaler.first; |
| 1578 | wait.seq = semaphore_state->signaler.second; |
| 1579 | submission.waitSemaphores.emplace_back(std::move(wait)); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1580 | semaphore_state->BeginUse(); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1581 | } |
| 1582 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 1583 | semaphore_state->signaled = false; |
| 1584 | } else if (semaphore_state->payload < value) { |
| 1585 | wait.queue = queue; |
| 1586 | wait.seq = next_seq; |
| 1587 | wait.payload = value; |
| 1588 | submission.waitSemaphores.emplace_back(std::move(wait)); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1589 | semaphore_state->BeginUse(); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1590 | } |
| 1591 | } else { |
| 1592 | submission.externalSemaphores.push_back(semaphore); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1593 | semaphore_state->BeginUse(); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1594 | if (semaphore_state->scope == kSyncScopeExternalTemporary) { |
| 1595 | semaphore_state->scope = kSyncScopeInternal; |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | bool ValidationStateTracker::RecordSubmitSignalSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore, |
| 1602 | uint64_t value, uint64_t next_seq) { |
| 1603 | bool retire_early = false; |
| 1604 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 1605 | if (semaphore_state) { |
| 1606 | if (semaphore_state->scope == kSyncScopeInternal) { |
| 1607 | SEMAPHORE_SIGNAL signal; |
| 1608 | signal.semaphore = semaphore; |
| 1609 | signal.seq = next_seq; |
| 1610 | if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) { |
| 1611 | semaphore_state->signaler.first = queue; |
| 1612 | semaphore_state->signaler.second = next_seq; |
| 1613 | semaphore_state->signaled = true; |
| 1614 | } else { |
| 1615 | signal.payload = value; |
| 1616 | } |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1617 | semaphore_state->BeginUse(); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1618 | submission.signalSemaphores.emplace_back(std::move(signal)); |
| 1619 | } else { |
| 1620 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
| 1621 | retire_early = true; |
| 1622 | } |
| 1623 | } |
| 1624 | return retire_early; |
| 1625 | } |
| 1626 | |
| 1627 | void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, |
| 1628 | VkFence fence, VkResult result) { |
| 1629 | if (result != VK_SUCCESS) return; |
| 1630 | auto queue_state = GetQueueState(queue); |
| 1631 | |
| 1632 | uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1633 | |
| 1634 | // Now process each individual submit |
| 1635 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1636 | CB_SUBMISSION submission; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1637 | const VkSubmitInfo *submit = &pSubmits[submit_idx]; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1638 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1639 | auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1640 | for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) { |
Jeremy Gebben | 4ae5cc7 | 2021-03-10 15:34:44 -0700 | [diff] [blame] | 1641 | uint64_t value = 0; |
| 1642 | if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr && |
| 1643 | (i < timeline_semaphore_submit->waitSemaphoreValueCount)) { |
| 1644 | value = timeline_semaphore_submit->pWaitSemaphoreValues[i]; |
| 1645 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1646 | RecordSubmitWaitSemaphore(submission, queue, submit->pWaitSemaphores[i], value, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1647 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1648 | |
| 1649 | bool retire_early = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1650 | for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) { |
Jeremy Gebben | 4ae5cc7 | 2021-03-10 15:34:44 -0700 | [diff] [blame] | 1651 | uint64_t value = 0; |
| 1652 | if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr && |
| 1653 | (i < timeline_semaphore_submit->signalSemaphoreValueCount)) { |
| 1654 | value = timeline_semaphore_submit->pSignalSemaphoreValues[i]; |
| 1655 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1656 | retire_early |= RecordSubmitSignalSemaphore(submission, queue, submit->pSignalSemaphores[i], value, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1657 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1658 | if (retire_early) { |
| 1659 | early_retire_seq = std::max(early_retire_seq, next_seq); |
| 1660 | } |
| 1661 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1662 | const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1663 | submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 1664 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1665 | for (uint32_t i = 0; i < submit->commandBufferCount; i++) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1666 | RecordSubmitCommandBuffer(submission, submit->pCommandBuffers[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1667 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1668 | submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE; |
| 1669 | queue_state->submissions.emplace_back(std::move(submission)); |
| 1670 | } |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 1671 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1672 | if (early_retire_seq) { |
| 1673 | RetireWorkOnQueue(queue_state, early_retire_seq); |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 1678 | VkFence fence, VkResult result) { |
| 1679 | if (result != VK_SUCCESS) return; |
| 1680 | auto queue_state = GetQueueState(queue); |
| 1681 | |
| 1682 | uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount); |
| 1683 | |
| 1684 | // Now process each individual submit |
| 1685 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 1686 | CB_SUBMISSION submission; |
| 1687 | const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx]; |
| 1688 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
| 1689 | for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) { |
| 1690 | const auto &sem_info = submit->pWaitSemaphoreInfos[i]; |
| 1691 | RecordSubmitWaitSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq); |
| 1692 | } |
| 1693 | bool retire_early = false; |
| 1694 | for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) { |
| 1695 | const auto &sem_info = submit->pSignalSemaphoreInfos[i]; |
| 1696 | retire_early |= RecordSubmitSignalSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq); |
| 1697 | } |
| 1698 | if (retire_early) { |
| 1699 | early_retire_seq = std::max(early_retire_seq, next_seq); |
| 1700 | } |
| 1701 | const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext); |
| 1702 | submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0; |
| 1703 | |
| 1704 | for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) { |
| 1705 | RecordSubmitCommandBuffer(submission, submit->pCommandBufferInfos[i].commandBuffer); |
| 1706 | } |
| 1707 | submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE; |
| 1708 | queue_state->submissions.emplace_back(std::move(submission)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | if (early_retire_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1712 | RetireWorkOnQueue(queue_state, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, |
| 1717 | const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory, |
| 1718 | VkResult result) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1719 | if (VK_SUCCESS != result) { |
| 1720 | return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1721 | } |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1722 | const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex]; |
| 1723 | const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex]; |
| 1724 | auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize); |
| 1725 | |
| 1726 | layer_data::optional<DedicatedBinding> dedicated_binding; |
| 1727 | |
| 1728 | auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext); |
| 1729 | if (dedicated) { |
| 1730 | if (dedicated->buffer) { |
| 1731 | const auto *buffer_state = GetBufferState(dedicated->buffer); |
| 1732 | assert(buffer_state); |
| 1733 | if (!buffer_state) { |
| 1734 | return; |
| 1735 | } |
| 1736 | dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo); |
| 1737 | } else if (dedicated->image) { |
| 1738 | const auto *image_state = GetImageState(dedicated->image); |
| 1739 | assert(image_state); |
| 1740 | if (!image_state) { |
| 1741 | return; |
| 1742 | } |
| 1743 | dedicated_binding.emplace(dedicated->image, image_state->createInfo); |
| 1744 | } |
| 1745 | } |
| 1746 | memObjMap[*pMemory] = std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap, |
| 1747 | std::move(dedicated_binding)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1748 | return; |
| 1749 | } |
| 1750 | |
| 1751 | void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) { |
| 1752 | if (!mem) return; |
| 1753 | DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1754 | if (!mem_info) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1755 | // Any bound cmd buffers are now invalid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1756 | mem_info->Destroy(); |
John Zulauf | 7995271 | 2020-04-07 11:25:54 -0600 | [diff] [blame] | 1757 | fake_memory.Free(mem_info->fake_base_address); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1758 | memObjMap.erase(mem); |
| 1759 | } |
| 1760 | |
| 1761 | void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo, |
| 1762 | VkFence fence, VkResult result) { |
| 1763 | if (result != VK_SUCCESS) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1764 | auto queue_state = GetQueueState(queue); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1765 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1766 | uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, bindInfoCount); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1767 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1768 | for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) { |
| 1769 | const VkBindSparseInfo &bind_info = pBindInfo[bind_idx]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1770 | // Track objects tied to memory |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1771 | for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) { |
| 1772 | for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) { |
| 1773 | auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1774 | auto buffer_state = GetBufferState(bind_info.pBufferBinds[j].buffer); |
| 1775 | auto mem_state = GetDevMemShared(sparse_binding.memory); |
| 1776 | if (buffer_state && mem_state) { |
| 1777 | buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size); |
| 1778 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1779 | } |
| 1780 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1781 | for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) { |
| 1782 | for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) { |
| 1783 | auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k]; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1784 | auto image_state = GetImageState(bind_info.pImageOpaqueBinds[j].image); |
| 1785 | auto mem_state = GetDevMemShared(sparse_binding.memory); |
| 1786 | if (image_state && mem_state) { |
| 1787 | image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size); |
| 1788 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1789 | } |
| 1790 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1791 | for (uint32_t j = 0; j < bind_info.imageBindCount; j++) { |
| 1792 | for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) { |
| 1793 | auto sparse_binding = bind_info.pImageBinds[j].pBinds[k]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1794 | // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data |
| 1795 | VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1796 | auto image_state = GetImageState(bind_info.pImageBinds[j].image); |
| 1797 | auto mem_state = GetDevMemShared(sparse_binding.memory); |
| 1798 | if (image_state && mem_state) { |
| 1799 | image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size); |
| 1800 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1801 | } |
| 1802 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1803 | CB_SUBMISSION submission; |
| 1804 | const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1805 | for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1806 | RecordSubmitWaitSemaphore(submission, queue, bind_info.pWaitSemaphores[i], 0, next_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1807 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1808 | bool retire_early = false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1809 | for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1810 | retire_early |= RecordSubmitSignalSemaphore(submission, queue, bind_info.pSignalSemaphores[i], 0, next_seq); |
| 1811 | } |
| 1812 | // Retire work up until this submit early, we will not see the wait that corresponds to this signal |
| 1813 | if (retire_early) { |
| 1814 | early_retire_seq = std::max(early_retire_seq, queue_state->seq + queue_state->submissions.size() + 1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1815 | } |
| 1816 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 1817 | submission.fence = bind_idx == (bindInfoCount - 1) ? fence : VK_NULL_HANDLE; |
| 1818 | queue_state->submissions.emplace_back(std::move(submission)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | if (early_retire_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1822 | RetireWorkOnQueue(queue_state, early_retire_seq); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, |
| 1827 | const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore, |
| 1828 | VkResult result) { |
| 1829 | if (VK_SUCCESS != result) return; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1830 | semaphoreMap[*pSemaphore] = std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1831 | } |
| 1832 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1833 | void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type, |
| 1834 | VkSemaphoreImportFlags flags) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1835 | SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore); |
| 1836 | if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1837 | if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) && |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1838 | sema_node->scope == kSyncScopeInternal) { |
| 1839 | sema_node->scope = kSyncScopeExternalTemporary; |
| 1840 | } else { |
| 1841 | sema_node->scope = kSyncScopeExternalPermanent; |
| 1842 | } |
| 1843 | } |
| 1844 | } |
| 1845 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1846 | void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo, |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 1847 | VkResult result) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1848 | auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore); |
| 1849 | semaphore_state->payload = pSignalInfo->value; |
Juan A. Suarez Romero | f302416 | 2019-10-31 17:57:50 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1852 | void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) { |
| 1853 | auto mem_info = GetDevMemState(mem); |
| 1854 | if (mem_info) { |
| 1855 | mem_info->mapped_range.offset = offset; |
| 1856 | mem_info->mapped_range.size = size; |
| 1857 | mem_info->p_driver_data = *ppData; |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | void ValidationStateTracker::RetireFence(VkFence fence) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1862 | auto fence_state = GetFenceState(fence); |
| 1863 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
| 1864 | if (fence_state->signaler.first != VK_NULL_HANDLE) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1865 | // Fence signaller is a queue -- use this as proof that prior operations on that queue have completed. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1866 | RetireWorkOnQueue(GetQueueState(fence_state->signaler.first), fence_state->signaler.second); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1867 | } else { |
| 1868 | // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark |
| 1869 | // the fence as retired. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1870 | fence_state->state = FENCE_RETIRED; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1871 | } |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 1876 | VkBool32 waitAll, uint64_t timeout, VkResult result) { |
| 1877 | if (VK_SUCCESS != result) return; |
| 1878 | |
| 1879 | // When we know that all fences are complete we can clean/remove their CBs |
| 1880 | if ((VK_TRUE == waitAll) || (1 == fenceCount)) { |
| 1881 | for (uint32_t i = 0; i < fenceCount; i++) { |
| 1882 | RetireFence(pFences[i]); |
| 1883 | } |
| 1884 | } |
| 1885 | // NOTE : Alternate case not handled here is when some fences have completed. In |
| 1886 | // this case for app to guarantee which fences completed it will have to call |
| 1887 | // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete. |
| 1888 | } |
| 1889 | |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 1890 | void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1891 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 1892 | if (semaphore_state) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 1893 | for (auto &pair : queueMap) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1894 | QUEUE_STATE &queue_state = pair.second; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 1895 | uint64_t max_seq = 0; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1896 | for (const auto &submission : queue_state.submissions) { |
| 1897 | for (const auto &signal_semaphore : submission.signalSemaphores) { |
| 1898 | if (signal_semaphore.semaphore == semaphore && signal_semaphore.payload <= until_payload) { |
| 1899 | if (signal_semaphore.seq > max_seq) { |
| 1900 | max_seq = signal_semaphore.seq; |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 1901 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 1902 | } |
| 1903 | } |
| 1904 | } |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 1905 | if (max_seq) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1906 | RetireWorkOnQueue(&queue_state, max_seq); |
Tony-LunarG | 47d5e27 | 2020-04-07 15:35:55 -0600 | [diff] [blame] | 1907 | } |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 1908 | } |
| 1909 | } |
| 1910 | } |
| 1911 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 1912 | void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 1913 | VkResult result) { |
Jakub Okoński | 04feb3b | 2020-02-01 18:31:01 +0100 | [diff] [blame] | 1914 | if (VK_SUCCESS != result) return; |
| 1915 | |
| 1916 | for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) { |
| 1917 | RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]); |
| 1918 | } |
| 1919 | } |
| 1920 | |
John Zulauf | f89de66 | 2020-04-13 18:57:34 -0600 | [diff] [blame] | 1921 | void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout, |
| 1922 | VkResult result) { |
| 1923 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 1924 | } |
| 1925 | |
| 1926 | void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, |
| 1927 | uint64_t timeout, VkResult result) { |
| 1928 | RecordWaitSemaphores(device, pWaitInfo, timeout, result); |
| 1929 | } |
| 1930 | |
Adrian Coca Lorente | c7d7610 | 2020-09-28 13:58:16 +0200 | [diff] [blame] | 1931 | void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 1932 | VkResult result) { |
| 1933 | if (VK_SUCCESS != result) return; |
| 1934 | |
| 1935 | RetireTimelineSemaphore(semaphore, *pValue); |
| 1936 | } |
| 1937 | |
| 1938 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 1939 | VkResult result) { |
| 1940 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 1941 | } |
| 1942 | void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue, |
| 1943 | VkResult result) { |
| 1944 | RecordGetSemaphoreCounterValue(device, semaphore, pValue, result); |
| 1945 | } |
| 1946 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1947 | void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) { |
| 1948 | if (VK_SUCCESS != result) return; |
| 1949 | RetireFence(fence); |
| 1950 | } |
| 1951 | |
| 1952 | void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) { |
Jeremy Gebben | 5573a8c | 2021-06-04 08:55:10 -0600 | [diff] [blame] | 1953 | queueMap.emplace(queue, QUEUE_STATE(queue, queue_family_index)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, |
| 1957 | VkQueue *pQueue) { |
| 1958 | RecordGetDeviceQueueState(queueFamilyIndex, *pQueue); |
| 1959 | } |
| 1960 | |
| 1961 | void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) { |
| 1962 | RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue); |
| 1963 | } |
| 1964 | |
| 1965 | void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) { |
| 1966 | if (VK_SUCCESS != result) return; |
| 1967 | QUEUE_STATE *queue_state = GetQueueState(queue); |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1968 | RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) { |
| 1972 | if (VK_SUCCESS != result) return; |
| 1973 | for (auto &queue : queueMap) { |
Jeff Bolz | 8041c5b | 2019-10-20 22:14:20 -0500 | [diff] [blame] | 1974 | RetireWorkOnQueue(&queue.second, queue.second.seq + queue.second.submissions.size()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
| 1978 | void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) { |
| 1979 | if (!fence) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 1980 | auto fence_state = GetFenceState(fence); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1981 | fence_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1982 | fenceMap.erase(fence); |
| 1983 | } |
| 1984 | |
| 1985 | void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore, |
| 1986 | const VkAllocationCallbacks *pAllocator) { |
| 1987 | if (!semaphore) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 1988 | auto semaphore_state = GetSemaphoreState(semaphore); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1989 | semaphore_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1990 | semaphoreMap.erase(semaphore); |
| 1991 | } |
| 1992 | |
| 1993 | void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) { |
| 1994 | if (!event) return; |
John Zulauf | 4805732 | 2020-12-02 11:59:31 -0700 | [diff] [blame] | 1995 | EVENT_STATE *event_state = Get<EVENT_STATE>(event); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1996 | event_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 1997 | eventMap.erase(event); |
| 1998 | } |
| 1999 | |
| 2000 | void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool, |
| 2001 | const VkAllocationCallbacks *pAllocator) { |
| 2002 | if (!queryPool) return; |
| 2003 | QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2004 | qp_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2005 | queryPoolMap.erase(queryPool); |
| 2006 | } |
| 2007 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2008 | void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) { |
| 2009 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2010 | if (buffer_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2011 | // Track objects tied to memory |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2012 | auto mem_state = GetDevMemShared(mem); |
| 2013 | if (mem_state) { |
| 2014 | buffer_state->SetMemBinding(mem_state, memoryOffset); |
| 2015 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, |
| 2020 | VkDeviceSize memoryOffset, VkResult result) { |
| 2021 | if (VK_SUCCESS != result) return; |
| 2022 | UpdateBindBufferMemoryState(buffer, mem, memoryOffset); |
| 2023 | } |
| 2024 | |
| 2025 | void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2026 | const VkBindBufferMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2027 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2028 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2033 | const VkBindBufferMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2034 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 2035 | UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset); |
| 2036 | } |
| 2037 | } |
| 2038 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2039 | void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2040 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 2041 | if (buffer_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2042 | buffer_state->memory_requirements_checked = true; |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, |
| 2047 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2048 | RecordGetBufferMemoryRequirementsState(buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2052 | const VkBufferMemoryRequirementsInfo2 *pInfo, |
| 2053 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2054 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2058 | const VkBufferMemoryRequirementsInfo2 *pInfo, |
| 2059 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2060 | RecordGetBufferMemoryRequirementsState(pInfo->buffer); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2061 | } |
| 2062 | |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2063 | void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2064 | const VkImagePlaneMemoryRequirementsInfo *plane_info = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2065 | (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2066 | IMAGE_STATE *image_state = GetImageState(image); |
| 2067 | if (image_state) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2068 | if (plane_info != nullptr) { |
| 2069 | // Multi-plane image |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2070 | if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 2071 | image_state->memory_requirements_checked[0] = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2072 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 2073 | image_state->memory_requirements_checked[1] = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2074 | } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 2075 | image_state->memory_requirements_checked[2] = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2076 | } |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 2077 | } else if (!image_state->disjoint) { |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2078 | // Single Plane image |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 2079 | image_state->memory_requirements_checked[0] = true; |
sfricke-samsung | d7ea5de | 2020-04-08 09:19:18 -0700 | [diff] [blame] | 2080 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image, |
| 2085 | VkMemoryRequirements *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2086 | RecordGetImageMemoryRequirementsState(image, nullptr); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2090 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2091 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device, |
| 2095 | const VkImageMemoryRequirementsInfo2 *pInfo, |
| 2096 | VkMemoryRequirements2 *pMemoryRequirements) { |
Spencer Fricke | 6c12710 | 2020-04-16 06:25:20 -0700 | [diff] [blame] | 2097 | RecordGetImageMemoryRequirementsState(pInfo->image, pInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | static void RecordGetImageSparseMemoryRequirementsState(IMAGE_STATE *image_state, |
| 2101 | VkSparseImageMemoryRequirements *sparse_image_memory_requirements) { |
| 2102 | image_state->sparse_requirements.emplace_back(*sparse_image_memory_requirements); |
| 2103 | if (sparse_image_memory_requirements->formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2104 | image_state->sparse_metadata_required = true; |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements( |
| 2109 | VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount, |
| 2110 | VkSparseImageMemoryRequirements *pSparseMemoryRequirements) { |
| 2111 | auto image_state = GetImageState(image); |
| 2112 | image_state->get_sparse_reqs_called = true; |
| 2113 | if (!pSparseMemoryRequirements) return; |
| 2114 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2115 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i]); |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2120 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2121 | VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2122 | auto image_state = GetImageState(pInfo->image); |
| 2123 | image_state->get_sparse_reqs_called = true; |
| 2124 | if (!pSparseMemoryRequirements) return; |
| 2125 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2126 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2127 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2132 | VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount, |
| 2133 | VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2134 | auto image_state = GetImageState(pInfo->image); |
| 2135 | image_state->get_sparse_reqs_called = true; |
| 2136 | if (!pSparseMemoryRequirements) return; |
| 2137 | for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) { |
| 2138 | assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it |
| 2139 | RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements); |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, |
| 2144 | const VkAllocationCallbacks *pAllocator) { |
| 2145 | if (!shaderModule) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2146 | auto shader_module_state = GetShaderModuleState(shaderModule); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2147 | shader_module_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2148 | shaderModuleMap.erase(shaderModule); |
| 2149 | } |
| 2150 | |
| 2151 | void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, |
| 2152 | const VkAllocationCallbacks *pAllocator) { |
| 2153 | if (!pipeline) return; |
| 2154 | PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2155 | // Any bound cmd buffers are now invalid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2156 | pipeline_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2157 | pipelineMap.erase(pipeline); |
| 2158 | } |
| 2159 | |
| 2160 | void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, |
| 2161 | const VkAllocationCallbacks *pAllocator) { |
| 2162 | if (!pipelineLayout) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2163 | auto pipeline_layout_state = GetPipelineLayout(pipelineLayout); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2164 | pipeline_layout_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2165 | pipelineLayoutMap.erase(pipelineLayout); |
| 2166 | } |
| 2167 | |
| 2168 | void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler, |
| 2169 | const VkAllocationCallbacks *pAllocator) { |
| 2170 | if (!sampler) return; |
| 2171 | SAMPLER_STATE *sampler_state = GetSamplerState(sampler); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2172 | // Any bound cmd buffers are now invalid |
| 2173 | if (sampler_state) { |
Yuly Novikov | 424cdd5 | 2020-05-26 16:45:12 -0400 | [diff] [blame] | 2174 | if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 2175 | sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
| 2176 | custom_border_color_sampler_count--; |
| 2177 | } |
| 2178 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2179 | sampler_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2180 | } |
| 2181 | samplerMap.erase(sampler); |
| 2182 | } |
| 2183 | |
| 2184 | void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, |
| 2185 | const VkAllocationCallbacks *pAllocator) { |
| 2186 | if (!descriptorSetLayout) return; |
| 2187 | auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout); |
| 2188 | if (layout_it != descriptorSetLayoutMap.end()) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2189 | layout_it->second.get()->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2190 | descriptorSetLayoutMap.erase(layout_it); |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 2195 | const VkAllocationCallbacks *pAllocator) { |
| 2196 | if (!descriptorPool) return; |
| 2197 | DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2198 | if (desc_pool_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2199 | // Free sets that were in this pool |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2200 | for (auto *ds : desc_pool_state->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2201 | FreeDescriptorSet(ds); |
| 2202 | } |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2203 | desc_pool_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2204 | descriptorPoolMap.erase(descriptorPool); |
| 2205 | } |
| 2206 | } |
| 2207 | |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2208 | // Free all command buffers in given list, removing all references/links to them using CMD_BUFFER_STATE::Reset |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2209 | void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count, |
| 2210 | const VkCommandBuffer *command_buffers) { |
| 2211 | for (uint32_t i = 0; i < command_buffer_count; i++) { |
| 2212 | auto cb_state = GetCBState(command_buffers[i]); |
| 2213 | // Remove references to command buffer's state and delete |
| 2214 | if (cb_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2215 | cb_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2216 | } |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2217 | // Remove CBState from CB map |
| 2218 | pool_state->commandBuffers.erase(command_buffers[i]); |
| 2219 | commandBufferMap.erase(command_buffers[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, |
| 2224 | uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2225 | auto pool = GetCommandPoolState(commandPool); |
| 2226 | FreeCommandBufferStates(pool, commandBufferCount, pCommandBuffers); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, |
| 2230 | const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool, |
| 2231 | VkResult result) { |
| 2232 | if (VK_SUCCESS != result) return; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 2233 | auto queue_flags = GetPhysicalDeviceState()->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags; |
| 2234 | commandPoolMap[*pCommandPool] = std::make_shared<COMMAND_POOL_STATE>(*pCommandPool, pCreateInfo, queue_flags); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo, |
| 2238 | const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool, |
| 2239 | VkResult result) { |
| 2240 | if (VK_SUCCESS != result) return; |
Jeremy Gebben | e9206ee | 2021-06-02 12:44:41 -0600 | [diff] [blame] | 2241 | |
| 2242 | uint32_t index_count = 0, n_perf_pass = 0; |
| 2243 | bool has_cb = false, has_rb = false; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2244 | if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2245 | const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext); |
Jeremy Gebben | e9206ee | 2021-06-02 12:44:41 -0600 | [diff] [blame] | 2246 | index_count = perf->counterIndexCount; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2247 | |
Mark Lobodzinski | 7e948e4 | 2020-09-09 10:23:36 -0600 | [diff] [blame] | 2248 | const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex]; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2249 | for (uint32_t i = 0; i < perf->counterIndexCount; i++) { |
| 2250 | const auto &counter = counters.counters[perf->pCounterIndices[i]]; |
| 2251 | switch (counter.scope) { |
| 2252 | case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR: |
Jeremy Gebben | e9206ee | 2021-06-02 12:44:41 -0600 | [diff] [blame] | 2253 | has_cb = true; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2254 | break; |
| 2255 | case VK_QUERY_SCOPE_RENDER_PASS_KHR: |
Jeremy Gebben | e9206ee | 2021-06-02 12:44:41 -0600 | [diff] [blame] | 2256 | has_rb = true; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2257 | break; |
| 2258 | default: |
| 2259 | break; |
| 2260 | } |
| 2261 | } |
| 2262 | |
Jeremy Gebben | e9206ee | 2021-06-02 12:44:41 -0600 | [diff] [blame] | 2263 | DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->phys_device, perf, &n_perf_pass); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 2264 | } |
| 2265 | |
Jeremy Gebben | e9206ee | 2021-06-02 12:44:41 -0600 | [diff] [blame] | 2266 | queryPoolMap[*pQueryPool] = |
| 2267 | std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2268 | |
| 2269 | QueryObject query_obj{*pQueryPool, 0u}; |
| 2270 | for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) { |
| 2271 | query_obj.query = i; |
| 2272 | queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, |
| 2277 | const VkAllocationCallbacks *pAllocator) { |
| 2278 | if (!commandPool) return; |
| 2279 | COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool); |
| 2280 | // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers |
| 2281 | // "When a pool is destroyed, all command buffers allocated from the pool are freed." |
| 2282 | if (cp_state) { |
| 2283 | // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration. |
| 2284 | std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()}; |
| 2285 | FreeCommandBufferStates(cp_state, static_cast<uint32_t>(cb_vec.size()), cb_vec.data()); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2286 | cp_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2287 | commandPoolMap.erase(commandPool); |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, |
| 2292 | VkCommandPoolResetFlags flags, VkResult result) { |
| 2293 | if (VK_SUCCESS != result) return; |
| 2294 | // Reset all of the CBs allocated from this pool |
| 2295 | auto command_pool_state = GetCommandPoolState(commandPool); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2296 | for (auto cmd_buffer : command_pool_state->commandBuffers) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2297 | auto cb_state = GetCBState(cmd_buffer); |
| 2298 | cb_state->Reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, |
| 2303 | VkResult result) { |
| 2304 | for (uint32_t i = 0; i < fenceCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2305 | auto fence_state = GetFenceState(pFences[i]); |
| 2306 | if (fence_state) { |
| 2307 | if (fence_state->scope == kSyncScopeInternal) { |
| 2308 | fence_state->state = FENCE_UNSIGNALED; |
| 2309 | } else if (fence_state->scope == kSyncScopeExternalTemporary) { |
| 2310 | fence_state->scope = kSyncScopeInternal; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2316 | void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, |
| 2317 | const VkAllocationCallbacks *pAllocator) { |
| 2318 | if (!framebuffer) return; |
| 2319 | FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2320 | framebuffer_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2321 | frameBufferMap.erase(framebuffer); |
| 2322 | } |
| 2323 | |
| 2324 | void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, |
| 2325 | const VkAllocationCallbacks *pAllocator) { |
| 2326 | if (!renderPass) return; |
| 2327 | RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2328 | rp_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2329 | renderPassMap.erase(renderPass); |
| 2330 | } |
| 2331 | |
| 2332 | void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, |
| 2333 | const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) { |
| 2334 | if (VK_SUCCESS != result) return; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2335 | fenceMap[*pFence] = std::make_shared<FENCE_STATE>(*pFence, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 2339 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 2340 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2341 | void *cgpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2342 | // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use. |
| 2343 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 2344 | cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 2345 | cgpl_state->pipe_state.reserve(count); |
| 2346 | for (uint32_t i = 0; i < count; i++) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2347 | cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 2348 | (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] | 2349 | (cgpl_state->pipe_state)[i]->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2350 | } |
| 2351 | return false; |
| 2352 | } |
| 2353 | |
| 2354 | void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 2355 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 2356 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 2357 | VkResult result, void *cgpl_state_data) { |
| 2358 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 2359 | // This API may create pipelines regardless of the return value |
| 2360 | for (uint32_t i = 0; i < count; i++) { |
| 2361 | if (pPipelines[i] != VK_NULL_HANDLE) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2362 | (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2363 | pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]); |
| 2364 | } |
| 2365 | } |
| 2366 | cgpl_state->pipe_state.clear(); |
| 2367 | } |
| 2368 | |
| 2369 | bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 2370 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 2371 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2372 | void *ccpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2373 | auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 2374 | ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis |
| 2375 | ccpl_state->pipe_state.reserve(count); |
| 2376 | for (uint32_t i = 0; i < count; i++) { |
| 2377 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2378 | ccpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2379 | ccpl_state->pipe_state.back()->initComputePipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2380 | ccpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2381 | } |
| 2382 | return false; |
| 2383 | } |
| 2384 | |
| 2385 | void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 2386 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 2387 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 2388 | VkResult result, void *ccpl_state_data) { |
| 2389 | create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 2390 | |
| 2391 | // This API may create pipelines regardless of the return value |
| 2392 | for (uint32_t i = 0; i < count; i++) { |
| 2393 | if (pPipelines[i] != VK_NULL_HANDLE) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2394 | (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2395 | pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]); |
| 2396 | } |
| 2397 | } |
| 2398 | ccpl_state->pipe_state.clear(); |
| 2399 | } |
| 2400 | |
| 2401 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, |
| 2402 | uint32_t count, |
| 2403 | const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 2404 | const VkAllocationCallbacks *pAllocator, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2405 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2406 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 2407 | crtpl_state->pipe_state.reserve(count); |
| 2408 | for (uint32_t i = 0; i < count; i++) { |
| 2409 | // Create and initialize internal tracking data structure |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2410 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2411 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2412 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2413 | } |
| 2414 | return false; |
| 2415 | } |
| 2416 | |
| 2417 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV( |
| 2418 | VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 2419 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) { |
| 2420 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
| 2421 | // This API may create pipelines regardless of the return value |
| 2422 | for (uint32_t i = 0; i < count; i++) { |
| 2423 | if (pPipelines[i] != VK_NULL_HANDLE) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2424 | (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2425 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 2426 | } |
| 2427 | } |
| 2428 | crtpl_state->pipe_state.clear(); |
| 2429 | } |
| 2430 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2431 | bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 2432 | VkPipelineCache pipelineCache, uint32_t count, |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2433 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 2434 | const VkAllocationCallbacks *pAllocator, |
| 2435 | VkPipeline *pPipelines, void *crtpl_state_data) const { |
| 2436 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 2437 | crtpl_state->pipe_state.reserve(count); |
| 2438 | for (uint32_t i = 0; i < count; i++) { |
| 2439 | // Create and initialize internal tracking data structure |
| 2440 | crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>()); |
| 2441 | crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]); |
| 2442 | crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout); |
| 2443 | } |
| 2444 | return false; |
| 2445 | } |
| 2446 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2447 | void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 2448 | VkPipelineCache pipelineCache, uint32_t count, |
| 2449 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 2450 | const VkAllocationCallbacks *pAllocator, |
| 2451 | VkPipeline *pPipelines, VkResult result, |
| 2452 | void *crtpl_state_data) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2453 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 2454 | // This API may create pipelines regardless of the return value |
| 2455 | for (uint32_t i = 0; i < count; i++) { |
| 2456 | if (pPipelines[i] != VK_NULL_HANDLE) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2457 | (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2458 | pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]); |
| 2459 | } |
| 2460 | } |
| 2461 | crtpl_state->pipe_state.clear(); |
| 2462 | } |
| 2463 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2464 | void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, |
| 2465 | const VkAllocationCallbacks *pAllocator, VkSampler *pSampler, |
| 2466 | VkResult result) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2467 | samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2468 | if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 2469 | pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) { |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 2470 | custom_border_color_sampler_count++; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2471 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device, |
| 2475 | const VkDescriptorSetLayoutCreateInfo *pCreateInfo, |
| 2476 | const VkAllocationCallbacks *pAllocator, |
| 2477 | VkDescriptorSetLayout *pSetLayout, VkResult result) { |
| 2478 | if (VK_SUCCESS != result) return; |
| 2479 | descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout); |
| 2480 | } |
| 2481 | |
| 2482 | // For repeatable sorting, not very useful for "memory in range" search |
| 2483 | struct PushConstantRangeCompare { |
| 2484 | bool operator()(const VkPushConstantRange *lhs, const VkPushConstantRange *rhs) const { |
| 2485 | if (lhs->offset == rhs->offset) { |
| 2486 | if (lhs->size == rhs->size) { |
| 2487 | // The comparison is arbitrary, but avoids false aliasing by comparing all fields. |
| 2488 | return lhs->stageFlags < rhs->stageFlags; |
| 2489 | } |
| 2490 | // If the offsets are the same then sorting by the end of range is useful for validation |
| 2491 | return lhs->size < rhs->size; |
| 2492 | } |
| 2493 | return lhs->offset < rhs->offset; |
| 2494 | } |
| 2495 | }; |
| 2496 | |
| 2497 | static PushConstantRangesDict push_constant_ranges_dict; |
| 2498 | |
| 2499 | PushConstantRangesId GetCanonicalId(const VkPipelineLayoutCreateInfo *info) { |
| 2500 | if (!info->pPushConstantRanges) { |
| 2501 | // Hand back the empty entry (creating as needed)... |
| 2502 | return push_constant_ranges_dict.look_up(PushConstantRanges()); |
| 2503 | } |
| 2504 | |
| 2505 | // Sort the input ranges to ensure equivalent ranges map to the same id |
| 2506 | std::set<const VkPushConstantRange *, PushConstantRangeCompare> sorted; |
| 2507 | for (uint32_t i = 0; i < info->pushConstantRangeCount; i++) { |
| 2508 | sorted.insert(info->pPushConstantRanges + i); |
| 2509 | } |
| 2510 | |
Jeremy Hayes | f34b9fb | 2019-12-06 09:37:03 -0700 | [diff] [blame] | 2511 | PushConstantRanges ranges; |
| 2512 | ranges.reserve(sorted.size()); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2513 | for (const auto *range : sorted) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2514 | ranges.emplace_back(*range); |
| 2515 | } |
| 2516 | return push_constant_ranges_dict.look_up(std::move(ranges)); |
| 2517 | } |
| 2518 | |
| 2519 | // Dictionary of canoncial form of the pipeline set layout of descriptor set layouts |
| 2520 | static PipelineLayoutSetLayoutsDict pipeline_layout_set_layouts_dict; |
| 2521 | |
| 2522 | // Dictionary of canonical form of the "compatible for set" records |
| 2523 | static PipelineLayoutCompatDict pipeline_layout_compat_dict; |
| 2524 | |
| 2525 | static PipelineLayoutCompatId GetCanonicalId(const uint32_t set_index, const PushConstantRangesId pcr_id, |
| 2526 | const PipelineLayoutSetLayoutsId set_layouts_id) { |
| 2527 | return pipeline_layout_compat_dict.look_up(PipelineLayoutCompatDef(set_index, pcr_id, set_layouts_id)); |
| 2528 | } |
| 2529 | |
| 2530 | void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, |
| 2531 | const VkAllocationCallbacks *pAllocator, |
| 2532 | VkPipelineLayout *pPipelineLayout, VkResult result) { |
| 2533 | if (VK_SUCCESS != result) return; |
| 2534 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2535 | auto pipeline_layout_state = std::make_shared<PIPELINE_LAYOUT_STATE>(*pPipelineLayout); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2536 | pipeline_layout_state->set_layouts.resize(pCreateInfo->setLayoutCount); |
| 2537 | PipelineLayoutSetLayoutsDef set_layouts(pCreateInfo->setLayoutCount); |
| 2538 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 2539 | pipeline_layout_state->set_layouts[i] = GetDescriptorSetLayoutShared(pCreateInfo->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2540 | set_layouts[i] = pipeline_layout_state->set_layouts[i]->GetLayoutId(); |
| 2541 | } |
| 2542 | |
| 2543 | // Get canonical form IDs for the "compatible for set" contents |
| 2544 | pipeline_layout_state->push_constant_ranges = GetCanonicalId(pCreateInfo); |
| 2545 | auto set_layouts_id = pipeline_layout_set_layouts_dict.look_up(set_layouts); |
| 2546 | pipeline_layout_state->compat_for_set.reserve(pCreateInfo->setLayoutCount); |
| 2547 | |
| 2548 | // Create table of "compatible for set N" cannonical forms for trivial accept validation |
| 2549 | for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) { |
| 2550 | pipeline_layout_state->compat_for_set.emplace_back( |
| 2551 | GetCanonicalId(i, pipeline_layout_state->push_constant_ranges, set_layouts_id)); |
| 2552 | } |
| 2553 | pipelineLayoutMap[*pPipelineLayout] = std::move(pipeline_layout_state); |
| 2554 | } |
| 2555 | |
| 2556 | void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo, |
| 2557 | const VkAllocationCallbacks *pAllocator, |
| 2558 | VkDescriptorPool *pDescriptorPool, VkResult result) { |
| 2559 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2560 | descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, |
| 2564 | VkDescriptorPoolResetFlags flags, VkResult result) { |
| 2565 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2566 | DESCRIPTOR_POOL_STATE *pool = GetDescriptorPoolState(descriptorPool); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2567 | // TODO: validate flags |
| 2568 | // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 2569 | for (auto *ds : pool->sets) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2570 | FreeDescriptorSet(ds); |
| 2571 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2572 | pool->sets.clear(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2573 | // Reset available count for each type and available sets for this pool |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2574 | for (auto it = pool->availableDescriptorTypeCount.begin(); it != pool->availableDescriptorTypeCount.end(); ++it) { |
| 2575 | pool->availableDescriptorTypeCount[it->first] = pool->maxDescriptorTypeCount[it->first]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2576 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2577 | pool->availableSets = pool->maxSets; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device, |
| 2581 | const VkDescriptorSetAllocateInfo *pAllocateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2582 | VkDescriptorSet *pDescriptorSets, void *ads_state_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2583 | // Always update common data |
| 2584 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 2585 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 2586 | UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state); |
| 2587 | |
| 2588 | return false; |
| 2589 | } |
| 2590 | |
| 2591 | // Allocation state was good and call down chain was made so update state based on allocating descriptor sets |
| 2592 | void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 2593 | VkDescriptorSet *pDescriptorSets, VkResult result, |
| 2594 | void *ads_state_data) { |
| 2595 | if (VK_SUCCESS != result) return; |
| 2596 | // All the updates are contained in a single cvdescriptorset function |
| 2597 | cvdescriptorset::AllocateDescriptorSetsData *ads_state = |
| 2598 | reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data); |
| 2599 | PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state); |
| 2600 | } |
| 2601 | |
| 2602 | void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, |
| 2603 | const VkDescriptorSet *pDescriptorSets) { |
| 2604 | DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool); |
| 2605 | // Update available descriptor sets in pool |
| 2606 | pool_state->availableSets += count; |
| 2607 | |
| 2608 | // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap |
| 2609 | for (uint32_t i = 0; i < count; ++i) { |
| 2610 | if (pDescriptorSets[i] != VK_NULL_HANDLE) { |
| 2611 | auto descriptor_set = setMap[pDescriptorSets[i]].get(); |
| 2612 | uint32_t type_index = 0, descriptor_count = 0; |
| 2613 | for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) { |
| 2614 | type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j)); |
| 2615 | descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j); |
| 2616 | pool_state->availableDescriptorTypeCount[type_index] += descriptor_count; |
| 2617 | } |
| 2618 | FreeDescriptorSet(descriptor_set); |
| 2619 | pool_state->sets.erase(descriptor_set); |
| 2620 | } |
| 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, |
| 2625 | const VkWriteDescriptorSet *pDescriptorWrites, |
| 2626 | uint32_t descriptorCopyCount, |
| 2627 | const VkCopyDescriptorSet *pDescriptorCopies) { |
| 2628 | cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, |
| 2629 | pDescriptorCopies); |
| 2630 | } |
| 2631 | |
| 2632 | void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, |
| 2633 | VkCommandBuffer *pCommandBuffer, VkResult result) { |
| 2634 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2635 | auto pool = GetCommandPoolShared(pCreateInfo->commandPool); |
| 2636 | if (pool) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2637 | for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) { |
| 2638 | // Add command buffer to its commandPool map |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2639 | pool->commandBuffers.insert(pCommandBuffer[i]); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2640 | commandBufferMap[pCommandBuffer[i]] = std::make_shared<CMD_BUFFER_STATE>(this, pCommandBuffer[i], pCreateInfo, pool); |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | } |
| 2644 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2645 | void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer, |
| 2646 | const VkCommandBufferBeginInfo *pBeginInfo) { |
| 2647 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2648 | if (!cb_state) return; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 2649 | |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2650 | cb_state->Begin(pBeginInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) { |
| 2654 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2655 | if (!cb_state) return; |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2656 | |
| 2657 | cb_state->End(result); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags, |
| 2661 | VkResult result) { |
| 2662 | if (VK_SUCCESS == result) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 2663 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2664 | cb_state->Reset(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | |
| 2668 | CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) { |
| 2669 | // initially assume everything is static state |
| 2670 | CBStatusFlags flags = CBSTATUS_ALL_STATE_SET; |
| 2671 | |
| 2672 | if (ds) { |
| 2673 | for (uint32_t i = 0; i < ds->dynamicStateCount; i++) { |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 2674 | flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2675 | } |
| 2676 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2677 | return flags; |
| 2678 | } |
| 2679 | |
| 2680 | // Validation cache: |
| 2681 | // CV is the bottommost implementor of this extension. Don't pass calls down. |
| 2682 | // utility function to set collective state for pipeline |
| 2683 | void SetPipelineState(PIPELINE_STATE *pPipe) { |
| 2684 | // If any attachment used by this pipeline has blendEnable, set top-level blendEnable |
| 2685 | if (pPipe->graphicsPipelineCI.pColorBlendState) { |
| 2686 | for (size_t i = 0; i < pPipe->attachments.size(); ++i) { |
| 2687 | if (VK_TRUE == pPipe->attachments[i].blendEnable) { |
| 2688 | if (((pPipe->attachments[i].dstAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 2689 | (pPipe->attachments[i].dstAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 2690 | ((pPipe->attachments[i].dstColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 2691 | (pPipe->attachments[i].dstColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 2692 | ((pPipe->attachments[i].srcAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 2693 | (pPipe->attachments[i].srcAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) || |
| 2694 | ((pPipe->attachments[i].srcColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) && |
| 2695 | (pPipe->attachments[i].srcColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA))) { |
| 2696 | pPipe->blendConstantsEnabled = true; |
| 2697 | } |
| 2698 | } |
| 2699 | } |
| 2700 | } |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 2701 | // Check if sample location is enabled |
| 2702 | if (pPipe->graphicsPipelineCI.pMultisampleState) { |
| 2703 | const VkPipelineSampleLocationsStateCreateInfoEXT *sample_location_state = |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2704 | LvlFindInChain<VkPipelineSampleLocationsStateCreateInfoEXT>(pPipe->graphicsPipelineCI.pMultisampleState->pNext); |
sfricke-samsung | 8f658d4 | 2020-05-03 20:12:24 -0700 | [diff] [blame] | 2705 | if (sample_location_state != nullptr) { |
| 2706 | pPipe->sample_location_enabled = sample_location_state->sampleLocationsEnable; |
| 2707 | } |
| 2708 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, |
| 2712 | VkPipeline pipeline) { |
| 2713 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2714 | assert(cb_state); |
| 2715 | |
| 2716 | auto pipe_state = GetPipelineState(pipeline); |
| 2717 | if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) { |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2718 | bool rasterization_enabled = VK_FALSE == pipe_state->graphicsPipelineCI.ptr()->pRasterizationState->rasterizerDiscardEnable; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2719 | const auto* viewport_state = pipe_state->graphicsPipelineCI.ptr()->pViewportState; |
| 2720 | const auto* dynamic_state = pipe_state->graphicsPipelineCI.ptr()->pDynamicState; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2721 | cb_state->status &= ~cb_state->static_status; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2722 | cb_state->static_status = MakeStaticStateMask(dynamic_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2723 | cb_state->status |= cb_state->static_status; |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 2724 | cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2725 | |
| 2726 | // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline. |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2727 | // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at |
| 2728 | // this time), then these are set to 0 to disable this checking. |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2729 | auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2730 | auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2731 | cb_state->pipelineStaticViewportCount = |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2732 | has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2733 | cb_state->pipelineStaticScissorCount = |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2734 | has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2735 | |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2736 | // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization. |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2737 | // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites |
| 2738 | // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count. |
| 2739 | // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver. |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2740 | if (!has_dynamic_viewport_count) { |
| 2741 | cb_state->trashedViewportCount = true; |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2742 | if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) { |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2743 | cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u; |
| 2744 | // should become = ~uint32_t(0) if the other interpretation is correct. |
| 2745 | } |
| 2746 | } |
| 2747 | if (!has_dynamic_scissor_count) { |
| 2748 | cb_state->trashedScissorCount = true; |
David Zhao Akeley | 5f40eb7 | 2021-05-04 21:56:14 -0700 | [diff] [blame] | 2749 | if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) { |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2750 | cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u; |
| 2751 | // should become = ~uint32_t(0) if the other interpretation is correct. |
| 2752 | } |
| 2753 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2754 | } |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 2755 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 2756 | cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2757 | SetPipelineState(pipe_state); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2758 | if (!disabled[command_buffer_state]) { |
| 2759 | cb_state->AddChild(pipe_state); |
| 2760 | } |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 2761 | for (auto &slot : pipe_state->active_slots) { |
| 2762 | for (auto &req : slot.second) { |
| 2763 | for (auto &sampler : req.second.samplers_used_by_image) { |
| 2764 | for (auto &des : sampler) { |
| 2765 | des.second = nullptr; |
| 2766 | } |
| 2767 | } |
| 2768 | } |
| 2769 | } |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 2770 | cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 2774 | uint32_t viewportCount, const VkViewport *pViewports) { |
| 2775 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2776 | uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport; |
| 2777 | cb_state->viewportMask |= bits; |
| 2778 | cb_state->trashedViewportMask &= ~bits; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2779 | cb_state->status |= CBSTATUS_VIEWPORT_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 2780 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 2781 | |
| 2782 | cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size())); |
| 2783 | for (size_t i = 0; i < viewportCount; ++i) { |
| 2784 | cb_state->dynamicViewports[firstViewport + i] = pViewports[i]; |
| 2785 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor, |
| 2789 | uint32_t exclusiveScissorCount, |
| 2790 | const VkRect2D *pExclusiveScissors) { |
| 2791 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2792 | // TODO: We don't have VUIDs for validating that all exclusive scissors have been set. |
| 2793 | // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor; |
| 2794 | cb_state->status |= CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 2795 | cb_state->static_status &= ~CBSTATUS_EXCLUSIVE_SCISSOR_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView, |
| 2799 | VkImageLayout imageLayout) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2800 | if (disabled[command_buffer_state]) return; |
| 2801 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2802 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2803 | |
| 2804 | if (imageView != VK_NULL_HANDLE) { |
| 2805 | auto view_state = GetImageViewState(imageView); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2806 | cb_state->AddChild(view_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 2811 | uint32_t viewportCount, |
| 2812 | const VkShadingRatePaletteNV *pShadingRatePalettes) { |
| 2813 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2814 | // TODO: We don't have VUIDs for validating that all shading rate palettes have been set. |
| 2815 | // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport; |
| 2816 | cb_state->status |= CBSTATUS_SHADING_RATE_PALETTE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 2817 | cb_state->static_status &= ~CBSTATUS_SHADING_RATE_PALETTE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device, |
| 2821 | const VkAccelerationStructureCreateInfoNV *pCreateInfo, |
| 2822 | const VkAllocationCallbacks *pAllocator, |
| 2823 | VkAccelerationStructureNV *pAccelerationStructure, |
| 2824 | VkResult result) { |
| 2825 | if (VK_SUCCESS != result) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2826 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2827 | |
| 2828 | // Query the requirements in case the application doesn't (to avoid bind/validation time query) |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 2829 | auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2830 | as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2831 | as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2832 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements); |
| 2833 | |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 2834 | auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2835 | scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2836 | scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2837 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info, |
| 2838 | &as_state->build_scratch_memory_requirements); |
| 2839 | |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 2840 | auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2841 | update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2842 | update_memory_req_info.accelerationStructure = as_state->acceleration_structure(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2843 | DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info, |
| 2844 | &as_state->update_scratch_memory_requirements); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 2845 | as_state->allocator = pAllocator; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2846 | accelerationStructureMap[*pAccelerationStructure] = std::move(as_state); |
| 2847 | } |
| 2848 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2849 | void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device, |
| 2850 | const VkAccelerationStructureCreateInfoKHR *pCreateInfo, |
| 2851 | const VkAllocationCallbacks *pAllocator, |
| 2852 | VkAccelerationStructureKHR *pAccelerationStructure, |
| 2853 | VkResult result) { |
| 2854 | if (VK_SUCCESS != result) return; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2855 | auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 2856 | as_state->allocator = pAllocator; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2857 | accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state); |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2858 | } |
| 2859 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2860 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR( |
| 2861 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 2862 | const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) { |
| 2863 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2864 | if (cb_state == nullptr) { |
| 2865 | return; |
| 2866 | } |
| 2867 | for (uint32_t i = 0; i < infoCount; ++i) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2868 | auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2869 | if (dst_as_state != nullptr) { |
| 2870 | dst_as_state->built = true; |
| 2871 | dst_as_state->build_info_khr.initialize(&pInfos[i]); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2872 | if (!disabled[command_buffer_state]) { |
| 2873 | cb_state->AddChild(dst_as_state); |
| 2874 | } |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2875 | } |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2876 | if (!disabled[command_buffer_state]) { |
| 2877 | auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure); |
| 2878 | if (src_as_state != nullptr) { |
| 2879 | cb_state->AddChild(src_as_state); |
| 2880 | } |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 2884 | } |
| 2885 | |
| 2886 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR( |
| 2887 | VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, |
| 2888 | const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides, |
| 2889 | const uint32_t *const *ppMaxPrimitiveCounts) { |
| 2890 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2891 | if (cb_state == nullptr) { |
| 2892 | return; |
| 2893 | } |
| 2894 | for (uint32_t i = 0; i < infoCount; ++i) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2895 | auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2896 | if (dst_as_state != nullptr) { |
| 2897 | dst_as_state->built = true; |
| 2898 | dst_as_state->build_info_khr.initialize(&pInfos[i]); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2899 | if (!disabled[command_buffer_state]) { |
| 2900 | cb_state->AddChild(dst_as_state); |
| 2901 | } |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2902 | } |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2903 | if (!disabled[command_buffer_state]) { |
| 2904 | auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure); |
| 2905 | if (src_as_state != nullptr) { |
| 2906 | cb_state->AddChild(src_as_state); |
| 2907 | } |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2908 | } |
| 2909 | } |
| 2910 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 2911 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2912 | void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 2913 | VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2914 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2915 | if (as_state != nullptr) { |
| 2916 | if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) { |
| 2917 | as_state->memory_requirements = *pMemoryRequirements; |
| 2918 | as_state->memory_requirements_checked = true; |
| 2919 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) { |
| 2920 | as_state->build_scratch_memory_requirements = *pMemoryRequirements; |
| 2921 | as_state->build_scratch_memory_requirements_checked = true; |
| 2922 | } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) { |
| 2923 | as_state->update_scratch_memory_requirements = *pMemoryRequirements; |
| 2924 | as_state->update_scratch_memory_requirements_checked = true; |
| 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2929 | void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV( |
| 2930 | VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2931 | if (VK_SUCCESS != result) return; |
| 2932 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2933 | const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i]; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2934 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2935 | ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2936 | if (as_state) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2937 | // Track objects tied to memory |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2938 | auto mem_state = GetDevMemShared(info.memory); |
| 2939 | if (mem_state) { |
| 2940 | as_state->SetMemBinding(mem_state, info.memoryOffset); |
| 2941 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2942 | |
| 2943 | // GPU validation of top level acceleration structure building needs acceleration structure handles. |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2944 | // XXX TODO: Query device address for KHR extension |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2945 | if (enabled[gpu_validation]) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2946 | DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle); |
| 2947 | } |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV( |
| 2953 | VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset, |
| 2954 | VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) { |
| 2955 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2956 | if (cb_state == nullptr) { |
| 2957 | return; |
| 2958 | } |
| 2959 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2960 | auto *dst_as_state = GetAccelerationStructureStateNV(dst); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2961 | if (dst_as_state != nullptr) { |
| 2962 | dst_as_state->built = true; |
| 2963 | dst_as_state->build_info.initialize(pInfo); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2964 | if (!disabled[command_buffer_state]) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2965 | cb_state->AddChild(dst_as_state); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2966 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2967 | } |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2968 | if (!disabled[command_buffer_state]) { |
| 2969 | auto *src_as_state = GetAccelerationStructureStateNV(src); |
| 2970 | if (src_as_state != nullptr) { |
| 2971 | cb_state->AddChild(src_as_state); |
| 2972 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2973 | } |
| 2974 | cb_state->hasBuildAccelerationStructureCmd = true; |
| 2975 | } |
| 2976 | |
| 2977 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer, |
| 2978 | VkAccelerationStructureNV dst, |
| 2979 | VkAccelerationStructureNV src, |
| 2980 | VkCopyAccelerationStructureModeNV mode) { |
| 2981 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 2982 | if (cb_state) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2983 | ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src); |
| 2984 | ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2985 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 2986 | dst_as_state->built = true; |
| 2987 | dst_as_state->build_info = src_as_state->build_info; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 2988 | if (!disabled[command_buffer_state]) { |
| 2989 | cb_state->AddChild(dst_as_state); |
| 2990 | cb_state->AddChild(src_as_state); |
| 2991 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2992 | } |
| 2993 | } |
| 2994 | } |
| 2995 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2996 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device, |
| 2997 | VkAccelerationStructureKHR accelerationStructure, |
| 2998 | const VkAllocationCallbacks *pAllocator) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 2999 | if (!accelerationStructure) return; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3000 | auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3001 | if (as_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3002 | as_state->Destroy(); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3003 | accelerationStructureMap_khr.erase(accelerationStructure); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3007 | void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device, |
| 3008 | VkAccelerationStructureNV accelerationStructure, |
| 3009 | const VkAllocationCallbacks *pAllocator) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3010 | if (!accelerationStructure) return; |
| 3011 | auto *as_state = GetAccelerationStructureStateNV(accelerationStructure); |
| 3012 | if (as_state) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3013 | as_state->Destroy(); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3014 | accelerationStructureMap.erase(accelerationStructure); |
| 3015 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3016 | } |
| 3017 | |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 3018 | void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport, |
| 3019 | uint32_t viewportCount, |
| 3020 | const VkViewportWScalingNV *pViewportWScalings) { |
| 3021 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3022 | cb_state->status |= CBSTATUS_VIEWPORT_W_SCALING_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3023 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_W_SCALING_SET; |
Chris Mayer | 9ded5eb | 2019-09-19 16:33:26 +0200 | [diff] [blame] | 3024 | } |
| 3025 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3026 | void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) { |
| 3027 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3028 | cb_state->status |= CBSTATUS_LINE_WIDTH_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3029 | cb_state->static_status &= ~CBSTATUS_LINE_WIDTH_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor, |
| 3033 | uint16_t lineStipplePattern) { |
| 3034 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3035 | cb_state->status |= CBSTATUS_LINE_STIPPLE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3036 | cb_state->static_status &= ~CBSTATUS_LINE_STIPPLE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, |
| 3040 | float depthBiasClamp, float depthBiasSlopeFactor) { |
| 3041 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3042 | cb_state->status |= CBSTATUS_DEPTH_BIAS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3043 | cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3044 | } |
| 3045 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3046 | void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, |
| 3047 | const VkRect2D *pScissors) { |
| 3048 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 3049 | uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor; |
| 3050 | cb_state->scissorMask |= bits; |
| 3051 | cb_state->trashedScissorMask &= ~bits; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3052 | cb_state->status |= CBSTATUS_SCISSOR_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3053 | cb_state->static_status &= ~CBSTATUS_SCISSOR_SET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 3054 | } |
| 3055 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3056 | void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) { |
| 3057 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3058 | cb_state->status |= CBSTATUS_BLEND_CONSTANTS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3059 | cb_state->static_status &= ~CBSTATUS_BLEND_CONSTANTS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds, |
| 3063 | float maxDepthBounds) { |
| 3064 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3065 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3066 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 3070 | uint32_t compareMask) { |
| 3071 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3072 | cb_state->status |= CBSTATUS_STENCIL_READ_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3073 | cb_state->static_status &= ~CBSTATUS_STENCIL_READ_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 3077 | uint32_t writeMask) { |
| 3078 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3079 | cb_state->status |= CBSTATUS_STENCIL_WRITE_MASK_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3080 | cb_state->static_status &= ~CBSTATUS_STENCIL_WRITE_MASK_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 3084 | uint32_t reference) { |
| 3085 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3086 | cb_state->status |= CBSTATUS_STENCIL_REFERENCE_SET; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3087 | cb_state->static_status &= ~CBSTATUS_STENCIL_REFERENCE_SET; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3088 | } |
| 3089 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3090 | |
| 3091 | // Update the bound state for the bind point, including the effects of incompatible pipeline layouts |
| 3092 | void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer, |
| 3093 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 3094 | uint32_t firstSet, uint32_t setCount, |
| 3095 | const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount, |
| 3096 | const uint32_t *pDynamicOffsets) { |
| 3097 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3098 | auto pipeline_layout = GetPipelineLayout(layout); |
| 3099 | |
| 3100 | // Resize binding arrays |
| 3101 | uint32_t last_set_index = firstSet + setCount - 1; |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3102 | const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint); |
| 3103 | if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) { |
| 3104 | cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3105 | } |
| 3106 | |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3107 | cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr, |
| 3108 | dynamicOffsetCount, pDynamicOffsets); |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 3109 | cb_state->lastBound[lv_bind_point].pipeline_layout = layout; |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 3110 | cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage(); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 3111 | } |
| 3112 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3113 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, |
| 3114 | VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 3115 | uint32_t set, uint32_t descriptorWriteCount, |
| 3116 | const VkWriteDescriptorSet *pDescriptorWrites) { |
| 3117 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3118 | auto pipeline_layout = GetPipelineLayout(layout); |
| 3119 | cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout, set, descriptorWriteCount, pDescriptorWrites); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3120 | } |
| 3121 | |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 3122 | void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout, |
| 3123 | VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, |
| 3124 | const void *pValues) { |
| 3125 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3126 | if (cb_state != nullptr) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3127 | cb_state->ResetPushConstantDataIfIncompatible(GetPipelineLayout(layout)); |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 3128 | |
| 3129 | auto &push_constant_data = cb_state->push_constant_data; |
| 3130 | assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size())); |
| 3131 | std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size)); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 3132 | cb_state->push_constant_pipeline_layout_set = layout; |
| 3133 | |
| 3134 | auto flags = stageFlags; |
| 3135 | uint32_t bit_shift = 0; |
| 3136 | while (flags) { |
| 3137 | if (flags & 1) { |
| 3138 | VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift); |
| 3139 | const auto it = cb_state->push_constant_data_update.find(flag); |
| 3140 | |
| 3141 | if (it != cb_state->push_constant_data_update.end()) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 3142 | std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size)); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 3143 | } |
| 3144 | } |
| 3145 | flags = flags >> 1; |
| 3146 | ++bit_shift; |
| 3147 | } |
Tony-LunarG | 6bb1d0c | 2019-09-23 10:39:25 -0600 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3151 | void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 3152 | VkIndexType indexType) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3153 | auto cb_state = GetCBState(commandBuffer); |
| 3154 | |
| 3155 | cb_state->status |= CBSTATUS_INDEX_BUFFER_BOUND; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3156 | cb_state->static_status &= ~CBSTATUS_INDEX_BUFFER_BOUND; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 3157 | cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer); |
| 3158 | cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3159 | cb_state->index_buffer_binding.offset = offset; |
| 3160 | cb_state->index_buffer_binding.index_type = indexType; |
| 3161 | // Add binding for this index buffer to this commandbuffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3162 | if (!disabled[command_buffer_state]) { |
| 3163 | cb_state->AddChild(cb_state->index_buffer_binding.buffer_state.get()); |
| 3164 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 3168 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 3169 | const VkDeviceSize *pOffsets) { |
| 3170 | auto cb_state = GetCBState(commandBuffer); |
| 3171 | |
| 3172 | uint32_t end = firstBinding + bindingCount; |
| 3173 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 3174 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 3175 | } |
| 3176 | |
| 3177 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 3178 | auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 3179 | vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3180 | vertex_buffer_binding.offset = pOffsets[i]; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 3181 | vertex_buffer_binding.size = VK_WHOLE_SIZE; |
| 3182 | vertex_buffer_binding.stride = 0; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3183 | // Add binding for this vertex buffer to this commandbuffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3184 | if (pBuffers[i] && !disabled[command_buffer_state]) { |
| 3185 | cb_state->AddChild(vertex_buffer_binding.buffer_state.get()); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3186 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, |
| 3191 | VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3192 | if (disabled[command_buffer_state]) return; |
| 3193 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3194 | auto cb_state = GetCBState(commandBuffer); |
| 3195 | auto dst_buffer_state = GetBufferState(dstBuffer); |
| 3196 | |
| 3197 | // Update bindings between buffer and cmd buffer |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 3198 | if (cb_state && dst_buffer_state) { |
| 3199 | cb_state->AddChild(dst_buffer_state); |
| 3200 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3201 | } |
| 3202 | |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 3203 | static bool SetEventStageMask(VkEvent event, VkPipelineStageFlags2KHR stageMask, |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 3204 | EventToStageMap *localEventToStageMap) { |
| 3205 | (*localEventToStageMap)[event] = stageMask; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3206 | return false; |
| 3207 | } |
| 3208 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3209 | void ValidationStateTracker::RecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3210 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3211 | if (!disabled[command_buffer_state]) { |
| 3212 | auto event_state = GetEventState(event); |
| 3213 | if (event_state) { |
| 3214 | cb_state->AddChild(event_state); |
| 3215 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3216 | } |
| 3217 | cb_state->events.push_back(event); |
| 3218 | if (!cb_state->waitedEvents.count(event)) { |
| 3219 | cb_state->writeEventsBeforeWait.push_back(event); |
| 3220 | } |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 3221 | cb_state->eventUpdates.emplace_back( |
| 3222 | [event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) { |
| 3223 | return SetEventStageMask(event, stageMask, localEventToStageMap); |
| 3224 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3225 | } |
| 3226 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3227 | void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 3228 | VkPipelineStageFlags stageMask) { |
| 3229 | RecordCmdSetEvent(commandBuffer, event, stageMask); |
| 3230 | } |
| 3231 | |
| 3232 | void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 3233 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 3234 | auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo); |
| 3235 | |
| 3236 | RecordCmdSetEvent(commandBuffer, event, stage_masks.src); |
Jeremy Gebben | 7964915 | 2021-06-22 14:46:24 -0600 | [diff] [blame] | 3237 | |
| 3238 | RecordBarriers(commandBuffer, pDependencyInfo); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | void ValidationStateTracker::RecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 3242 | VkPipelineStageFlags2KHR stageMask) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3243 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3244 | if (!disabled[command_buffer_state]) { |
| 3245 | auto event_state = GetEventState(event); |
| 3246 | if (event_state) { |
| 3247 | cb_state->AddChild(event_state); |
| 3248 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3249 | } |
| 3250 | cb_state->events.push_back(event); |
| 3251 | if (!cb_state->waitedEvents.count(event)) { |
| 3252 | cb_state->writeEventsBeforeWait.push_back(event); |
| 3253 | } |
| 3254 | |
| 3255 | cb_state->eventUpdates.emplace_back( |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 3256 | [event](const ValidationStateTracker *, bool do_validate, EventToStageMap *localEventToStageMap) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3257 | return SetEventStageMask(event, VkPipelineStageFlags2KHR(0), localEventToStageMap); |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 3258 | }); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3259 | } |
| 3260 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3261 | void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, |
| 3262 | VkPipelineStageFlags stageMask) { |
| 3263 | RecordCmdResetEvent(commandBuffer, event, stageMask); |
| 3264 | } |
| 3265 | |
| 3266 | void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event, |
| 3267 | VkPipelineStageFlags2KHR stageMask) { |
| 3268 | RecordCmdResetEvent(commandBuffer, event, stageMask); |
| 3269 | } |
| 3270 | |
| 3271 | void ValidationStateTracker::RecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3272 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3273 | for (uint32_t i = 0; i < eventCount; ++i) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3274 | if (!disabled[command_buffer_state]) { |
| 3275 | auto event_state = GetEventState(pEvents[i]); |
| 3276 | if (event_state) { |
| 3277 | cb_state->AddChild(event_state); |
| 3278 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3279 | } |
| 3280 | cb_state->waitedEvents.insert(pEvents[i]); |
| 3281 | cb_state->events.push_back(pEvents[i]); |
| 3282 | } |
| 3283 | } |
| 3284 | |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3285 | void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 3286 | VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask, |
| 3287 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3288 | uint32_t bufferMemoryBarrierCount, |
| 3289 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3290 | uint32_t imageMemoryBarrierCount, |
| 3291 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 3292 | RecordCmdWaitEvents(commandBuffer, eventCount, pEvents); |
Jeremy Gebben | 7964915 | 2021-06-22 14:46:24 -0600 | [diff] [blame] | 3293 | RecordBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 3294 | imageMemoryBarrierCount, pImageMemoryBarriers); |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, |
| 3298 | const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) { |
| 3299 | RecordCmdWaitEvents(commandBuffer, eventCount, pEvents); |
Jeremy Gebben | 7964915 | 2021-06-22 14:46:24 -0600 | [diff] [blame] | 3300 | for (uint32_t i = 0; i < eventCount; i++) { |
| 3301 | RecordBarriers(commandBuffer, &pDependencyInfos[i]); |
| 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 3306 | VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 3307 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 3308 | uint32_t bufferMemoryBarrierCount, |
| 3309 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 3310 | uint32_t imageMemoryBarrierCount, |
| 3311 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 3312 | RecordBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, |
| 3313 | imageMemoryBarrierCount, pImageMemoryBarriers); |
| 3314 | } |
| 3315 | |
| 3316 | void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, |
| 3317 | const VkDependencyInfoKHR *pDependencyInfo) { |
| 3318 | RecordBarriers(commandBuffer, pDependencyInfo); |
| 3319 | } |
| 3320 | |
| 3321 | void ValidationStateTracker::RecordBarriers(VkCommandBuffer commandBuffer, uint32_t memoryBarrierCount, |
| 3322 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, |
| 3323 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 3324 | const VkImageMemoryBarrier *pImageMemoryBarriers) { |
| 3325 | if (disabled[command_buffer_state]) return; |
| 3326 | |
| 3327 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3328 | for (uint32_t i = 0; i < bufferMemoryBarrierCount; i++) { |
| 3329 | auto buffer_state = GetBufferState(pBufferMemoryBarriers[i].buffer); |
| 3330 | if (buffer_state) { |
| 3331 | cb_state->AddChild(buffer_state); |
| 3332 | } |
| 3333 | } |
| 3334 | for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) { |
| 3335 | auto image_state = GetImageState(pImageMemoryBarriers[i].image); |
| 3336 | if (image_state) { |
| 3337 | cb_state->AddChild(image_state); |
| 3338 | } |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | void ValidationStateTracker::RecordBarriers(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) { |
| 3343 | if (disabled[command_buffer_state]) return; |
| 3344 | |
| 3345 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3346 | for (uint32_t i = 0; i < pDependencyInfo->bufferMemoryBarrierCount; i++) { |
| 3347 | auto buffer_state = GetBufferState(pDependencyInfo->pBufferMemoryBarriers[i].buffer); |
| 3348 | if (buffer_state) { |
| 3349 | cb_state->AddChild(buffer_state); |
| 3350 | } |
| 3351 | } |
| 3352 | for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; i++) { |
| 3353 | auto image_state = GetImageState(pDependencyInfo->pImageMemoryBarriers[i].image); |
| 3354 | if (image_state) { |
| 3355 | cb_state->AddChild(image_state); |
| 3356 | } |
| 3357 | } |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 3360 | QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex, |
| 3361 | uint32_t perfPass) const { |
| 3362 | QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3363 | |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 3364 | auto iter = localQueryToStateMap->find(query); |
| 3365 | if (iter != localQueryToStateMap->end()) return iter->second; |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 3366 | |
Jeff Bolz | 310775c | 2019-10-09 00:46:33 -0500 | [diff] [blame] | 3367 | return QUERYSTATE_UNKNOWN; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3368 | } |
| 3369 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3370 | void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, |
| 3371 | VkFlags flags) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 3372 | if (disabled[query_validation]) return; |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3373 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3374 | QueryObject query = {queryPool, slot}; |
| 3375 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3376 | if (!disabled[query_validation]) { |
| 3377 | cb_state->BeginQuery(query); |
| 3378 | } |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3379 | if (!disabled[command_buffer_state]) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3380 | auto pool_state = GetQueryPoolState(query.pool); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3381 | cb_state->AddChild(pool_state); |
| 3382 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 3386 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3387 | QueryObject query_obj = {queryPool, slot}; |
| 3388 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3389 | if (!disabled[query_validation]) { |
| 3390 | cb_state->EndQuery(query_obj); |
| 3391 | } |
| 3392 | if (!disabled[command_buffer_state]) { |
| 3393 | auto pool_state = GetQueryPoolState(query_obj.pool); |
| 3394 | cb_state->AddChild(pool_state); |
| 3395 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 3399 | uint32_t firstQuery, uint32_t queryCount) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 3400 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3401 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3402 | |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3403 | cb_state->ResetQueryPool(queryPool, firstQuery, queryCount); |
Lionel Landwerlin | b1e5a42 | 2020-02-18 16:49:09 +0200 | [diff] [blame] | 3404 | |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3405 | if (!disabled[command_buffer_state]) { |
| 3406 | auto pool_state = GetQueryPoolState(queryPool); |
| 3407 | cb_state->AddChild(pool_state); |
| 3408 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 3412 | uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, |
| 3413 | VkDeviceSize dstOffset, VkDeviceSize stride, |
| 3414 | VkQueryResultFlags flags) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3415 | if (disabled[query_validation] || disabled[command_buffer_state]) return; |
| 3416 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3417 | auto cb_state = GetCBState(commandBuffer); |
| 3418 | auto dst_buff_state = GetBufferState(dstBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3419 | cb_state->AddChild(dst_buff_state); |
Jeff Bolz | adbfa85 | 2019-10-04 13:53:30 -0500 | [diff] [blame] | 3420 | auto pool_state = GetQueryPoolState(queryPool); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3421 | cb_state->AddChild(pool_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, |
| 3425 | VkQueryPool queryPool, uint32_t slot) { |
Jeremy Gebben | 74aa762 | 2020-12-15 11:18:00 -0700 | [diff] [blame] | 3426 | PostCallRecordCmdWriteTimestamp2KHR(commandBuffer, pipelineStage, queryPool, slot); |
| 3427 | } |
| 3428 | |
| 3429 | void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer, |
| 3430 | VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool, |
| 3431 | uint32_t slot) { |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 3432 | if (disabled[query_validation]) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3433 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3434 | if (!disabled[command_buffer_state]) { |
| 3435 | auto pool_state = GetQueryPoolState(queryPool); |
| 3436 | cb_state->AddChild(pool_state); |
| 3437 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3438 | QueryObject query = {queryPool, slot}; |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3439 | cb_state->EndQuery(query); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3440 | } |
| 3441 | |
Marijn Suijten | 6750fdc | 2020-12-30 22:06:42 +0100 | [diff] [blame] | 3442 | void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR( |
| 3443 | VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures, |
| 3444 | VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) { |
| 3445 | if (disabled[query_validation]) return; |
| 3446 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3447 | if (!disabled[command_buffer_state]) { |
| 3448 | auto pool_state = GetQueryPoolState(queryPool); |
| 3449 | cb_state->AddChild(pool_state); |
| 3450 | } |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3451 | cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount); |
Marijn Suijten | 6750fdc | 2020-12-30 22:06:42 +0100 | [diff] [blame] | 3452 | } |
| 3453 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3454 | void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo, |
| 3455 | const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer, |
| 3456 | VkResult result) { |
| 3457 | if (VK_SUCCESS != result) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3458 | |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3459 | std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3460 | if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) { |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3461 | views.resize(pCreateInfo->attachmentCount); |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 3462 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3463 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3464 | views[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3465 | } |
| 3466 | } |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3467 | |
| 3468 | frameBufferMap[*pFramebuffer] = std::make_shared<FRAMEBUFFER_STATE>( |
| 3469 | *pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass), std::move(views)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3470 | } |
| 3471 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3472 | void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, |
| 3473 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 3474 | VkResult result) { |
| 3475 | if (VK_SUCCESS != result) return; |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3476 | renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3477 | } |
| 3478 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3479 | void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo, |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3480 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 3481 | VkResult result) { |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3482 | if (VK_SUCCESS != result) return; |
| 3483 | |
| 3484 | renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3487 | void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo, |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3488 | const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass, |
| 3489 | VkResult result) { |
Jeremy Gebben | 88f5814 | 2021-06-01 10:07:52 -0600 | [diff] [blame] | 3490 | if (VK_SUCCESS != result) return; |
| 3491 | |
| 3492 | renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3495 | void ValidationStateTracker::RecordCmdBeginRenderPassState(VkCommandBuffer commandBuffer, |
| 3496 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3497 | const VkSubpassContents contents) { |
| 3498 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3499 | cb_state->BeginRenderPass(pRenderPassBegin, contents); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer, |
| 3503 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 3504 | VkSubpassContents contents) { |
| 3505 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, contents); |
| 3506 | } |
| 3507 | |
| 3508 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, |
| 3509 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3510 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3511 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 3512 | } |
| 3513 | |
Jeremy Hayes | 9bda85a | 2020-05-21 16:36:17 -0600 | [diff] [blame] | 3514 | void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 3515 | uint32_t counterBufferCount, |
| 3516 | const VkBuffer *pCounterBuffers, |
| 3517 | const VkDeviceSize *pCounterBufferOffsets) { |
| 3518 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3519 | |
| 3520 | cb_state->transform_feedback_active = true; |
| 3521 | } |
| 3522 | |
| 3523 | void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer, |
| 3524 | uint32_t counterBufferCount, const VkBuffer *pCounterBuffers, |
| 3525 | const VkDeviceSize *pCounterBufferOffsets) { |
| 3526 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3527 | |
| 3528 | cb_state->transform_feedback_active = false; |
| 3529 | } |
| 3530 | |
ziga-lunarg | 40f5fbc | 2021-08-14 23:06:41 +0200 | [diff] [blame^] | 3531 | void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT( |
| 3532 | VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) { |
| 3533 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3534 | |
| 3535 | cb_state->conditional_rendering_active = true; |
| 3536 | } |
| 3537 | |
| 3538 | void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) { |
| 3539 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3540 | |
| 3541 | cb_state->conditional_rendering_active = false; |
| 3542 | |
| 3543 | } |
| 3544 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3545 | void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer, |
| 3546 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3547 | const VkSubpassBeginInfo *pSubpassBeginInfo) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3548 | RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents); |
| 3549 | } |
| 3550 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3551 | void ValidationStateTracker::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3552 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3553 | cb_state->NextSubpass(contents); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) { |
| 3557 | RecordCmdNextSubpass(commandBuffer, contents); |
| 3558 | } |
| 3559 | |
| 3560 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3561 | const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3562 | const VkSubpassEndInfo *pSubpassEndInfo) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3563 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 3564 | } |
| 3565 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3566 | void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3567 | const VkSubpassBeginInfo *pSubpassBeginInfo, |
| 3568 | const VkSubpassEndInfo *pSubpassEndInfo) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3569 | RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents); |
| 3570 | } |
| 3571 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3572 | void ValidationStateTracker::RecordCmdEndRenderPassState(VkCommandBuffer commandBuffer) { |
| 3573 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3574 | cb_state->EndRenderPass(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) { |
| 3578 | RecordCmdEndRenderPassState(commandBuffer); |
| 3579 | } |
| 3580 | |
| 3581 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3582 | const VkSubpassEndInfo *pSubpassEndInfo) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3583 | RecordCmdEndRenderPassState(commandBuffer); |
| 3584 | } |
| 3585 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3586 | void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3587 | const VkSubpassEndInfo *pSubpassEndInfo) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 3588 | RecordCmdEndRenderPassState(commandBuffer); |
| 3589 | } |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3590 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3591 | void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, |
| 3592 | const VkCommandBuffer *pCommandBuffers) { |
| 3593 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 3594 | |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 3595 | cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, |
| 3599 | VkFlags flags, void **ppData, VkResult result) { |
| 3600 | if (VK_SUCCESS != result) return; |
| 3601 | RecordMappedMemory(mem, offset, size, ppData); |
| 3602 | } |
| 3603 | |
| 3604 | void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) { |
| 3605 | auto mem_info = GetDevMemState(mem); |
| 3606 | if (mem_info) { |
| 3607 | mem_info->mapped_range = MemRange(); |
| 3608 | mem_info->p_driver_data = nullptr; |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) { |
Jeremy Gebben | 8ee02af | 2021-07-16 10:15:55 -0600 | [diff] [blame] | 3613 | auto image_state = GetShared<IMAGE_STATE>(bindInfo.image); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3614 | if (image_state) { |
locke-lunarg | ae26eac | 2020-04-16 15:29:05 -0600 | [diff] [blame] | 3615 | // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory. |
| 3616 | // See: VUID-vkGetImageSubresourceLayout-image-01895 |
| 3617 | image_state->fragment_encoder = |
| 3618 | std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state)); |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3619 | const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3620 | if (swapchain_info) { |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 3621 | auto swapchain = GetShared<SWAPCHAIN_NODE>(swapchain_info->swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3622 | if (swapchain) { |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 3623 | SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex]; |
John Zulauf | d13b38e | 2021-03-05 08:17:38 -0700 | [diff] [blame] | 3624 | |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 3625 | if (!swapchain_image.fake_base_address) { |
| 3626 | auto size = image_state->fragment_encoder->TotalSize(); |
| 3627 | swapchain_image.fake_base_address = fake_memory.Alloc(size); |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 3628 | } |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 3629 | // All images bound to this swapchain and index are aliases |
| 3630 | image_state->SetSwapchain(swapchain, swapchain_info->imageIndex); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3631 | } |
| 3632 | } else { |
| 3633 | // Track bound memory range information |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3634 | auto mem_info = GetDevMemShared(bindInfo.memory); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3635 | if (mem_info) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3636 | image_state->SetMemBinding(mem_info, bindInfo.memoryOffset); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3637 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3638 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem, |
| 3643 | VkDeviceSize memoryOffset, VkResult result) { |
| 3644 | if (VK_SUCCESS != result) return; |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 3645 | auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3646 | bind_info.image = image; |
| 3647 | bind_info.memory = mem; |
| 3648 | bind_info.memoryOffset = memoryOffset; |
| 3649 | UpdateBindImageMemoryState(bind_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3653 | const VkBindImageMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3654 | if (VK_SUCCESS != result) return; |
| 3655 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 3656 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3661 | const VkBindImageMemoryInfo *pBindInfos, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3662 | if (VK_SUCCESS != result) return; |
| 3663 | for (uint32_t i = 0; i < bindInfoCount; i++) { |
| 3664 | UpdateBindImageMemoryState(pBindInfos[i]); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) { |
| 3669 | auto event_state = GetEventState(event); |
| 3670 | if (event_state) { |
| 3671 | event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT; |
| 3672 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device, |
| 3676 | const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo, |
| 3677 | VkResult result) { |
| 3678 | if (VK_SUCCESS != result) return; |
| 3679 | RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType, |
| 3680 | pImportSemaphoreFdInfo->flags); |
| 3681 | } |
| 3682 | |
| 3683 | void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3684 | VkExternalSemaphoreHandleTypeFlagBits handle_type) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3685 | SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3686 | if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3687 | // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference |
| 3688 | semaphore_state->scope = kSyncScopeExternalPermanent; |
| 3689 | } |
| 3690 | } |
| 3691 | |
| 3692 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 3693 | void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR( |
| 3694 | VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) { |
| 3695 | if (VK_SUCCESS != result) return; |
| 3696 | RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType, |
| 3697 | pImportSemaphoreWin32HandleInfo->flags); |
| 3698 | } |
| 3699 | |
| 3700 | void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device, |
| 3701 | const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 3702 | HANDLE *pHandle, VkResult result) { |
| 3703 | if (VK_SUCCESS != result) return; |
| 3704 | RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType); |
| 3705 | } |
| 3706 | |
| 3707 | void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR( |
| 3708 | VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) { |
| 3709 | if (VK_SUCCESS != result) return; |
| 3710 | RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType, |
| 3711 | pImportFenceWin32HandleInfo->flags); |
| 3712 | } |
| 3713 | |
| 3714 | void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device, |
| 3715 | const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo, |
| 3716 | HANDLE *pHandle, VkResult result) { |
| 3717 | if (VK_SUCCESS != result) return; |
| 3718 | RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType); |
| 3719 | } |
| 3720 | #endif |
| 3721 | |
| 3722 | void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 3723 | VkResult result) { |
| 3724 | if (VK_SUCCESS != result) return; |
| 3725 | RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType); |
| 3726 | } |
| 3727 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3728 | void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type, |
| 3729 | VkFenceImportFlags flags) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3730 | FENCE_STATE *fence_node = GetFenceState(fence); |
| 3731 | if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3732 | if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) && |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3733 | fence_node->scope == kSyncScopeInternal) { |
| 3734 | fence_node->scope = kSyncScopeExternalTemporary; |
| 3735 | } else { |
| 3736 | fence_node->scope = kSyncScopeExternalPermanent; |
| 3737 | } |
| 3738 | } |
| 3739 | } |
| 3740 | |
| 3741 | void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo, |
| 3742 | VkResult result) { |
| 3743 | if (VK_SUCCESS != result) return; |
| 3744 | RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags); |
| 3745 | } |
| 3746 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3747 | void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3748 | FENCE_STATE *fence_state = GetFenceState(fence); |
| 3749 | if (fence_state) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3750 | if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3751 | // Export with reference transference becomes external |
| 3752 | fence_state->scope = kSyncScopeExternalPermanent; |
| 3753 | } else if (fence_state->scope == kSyncScopeInternal) { |
| 3754 | // Export with copy transference has a side effect of resetting the fence |
| 3755 | fence_state->state = FENCE_UNSIGNALED; |
| 3756 | } |
| 3757 | } |
| 3758 | } |
| 3759 | |
| 3760 | void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd, |
| 3761 | VkResult result) { |
| 3762 | if (VK_SUCCESS != result) return; |
| 3763 | RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType); |
| 3764 | } |
| 3765 | |
| 3766 | void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo, |
| 3767 | const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) { |
| 3768 | if (VK_SUCCESS != result) return; |
John Zulauf | d511570 | 2021-01-18 12:34:33 -0700 | [diff] [blame] | 3769 | const auto event = *pEvent; |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 3770 | eventMap.emplace(event, std::make_shared<EVENT_STATE>(event, pCreateInfo->flags)); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo, |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3774 | VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3775 | SWAPCHAIN_NODE *old_swapchain_state) { |
| 3776 | if (VK_SUCCESS == result) { |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 3777 | if (surface_state->swapchain) { |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3778 | surface_state->RemoveParent(surface_state->swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3779 | } |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3780 | auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain); |
| 3781 | surface_state->AddParent(swapchain.get()); |
| 3782 | surface_state->swapchain = swapchain.get(); |
| 3783 | swapchain->surface = std::move(surface_state); |
| 3784 | swapchainMap[*pSwapchain] = std::move(swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3785 | } else { |
| 3786 | surface_state->swapchain = nullptr; |
| 3787 | } |
| 3788 | // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3789 | // Retired swapchains remain associated with the surface until they are destroyed. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3790 | if (old_swapchain_state) { |
| 3791 | old_swapchain_state->retired = true; |
| 3792 | } |
| 3793 | return; |
| 3794 | } |
| 3795 | |
| 3796 | void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 3797 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain, |
| 3798 | VkResult result) { |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3799 | auto surface_state = GetShared<SURFACE_STATE>(pCreateInfo->surface); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3800 | auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain); |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3801 | RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 3805 | const VkAllocationCallbacks *pAllocator) { |
| 3806 | if (!swapchain) return; |
| 3807 | auto swapchain_data = GetSwapchainState(swapchain); |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 3808 | if (!swapchain_data) return; |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 3809 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 3810 | swapchain_data->Destroy(); |
| 3811 | swapchainMap.erase(swapchain); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3812 | } |
| 3813 | |
sfricke-samsung | 5c1b739 | 2020-12-13 22:17:15 -0800 | [diff] [blame] | 3814 | void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, |
| 3815 | const VkDisplayModeCreateInfoKHR *pCreateInfo, |
| 3816 | const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode, |
| 3817 | VkResult result) { |
| 3818 | if (VK_SUCCESS != result) return; |
| 3819 | if (!pMode) return; |
Jeremy Gebben | 5573a8c | 2021-06-04 08:55:10 -0600 | [diff] [blame] | 3820 | display_mode_map[*pMode] = std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice); |
sfricke-samsung | 5c1b739 | 2020-12-13 22:17:15 -0800 | [diff] [blame] | 3821 | } |
| 3822 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3823 | void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) { |
| 3824 | // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?) |
| 3825 | for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3826 | auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]); |
| 3827 | if (semaphore_state) { |
| 3828 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
| 3829 | semaphore_state->signaled = false; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | |
Tony-LunarG | 6f887e5 | 2021-07-27 11:23:14 -0600 | [diff] [blame] | 3833 | const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3834 | for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { |
| 3835 | // 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 |
| 3836 | // confused itself just as much. |
| 3837 | auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result; |
| 3838 | if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen. |
| 3839 | // Mark the image as having been released to the WSI |
| 3840 | auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]); |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 3841 | if (swapchain_data) { |
| 3842 | swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]); |
Tony-LunarG | 6f887e5 | 2021-07-27 11:23:14 -0600 | [diff] [blame] | 3843 | if (present_id_info) { |
| 3844 | if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) { |
| 3845 | swapchain_data->max_present_id = present_id_info->pPresentIds[i]; |
| 3846 | } |
| 3847 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3848 | } |
| 3849 | } |
| 3850 | // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and |
| 3851 | // its semaphore waits) /never/ participate in any completion proof. |
| 3852 | } |
| 3853 | |
| 3854 | void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount, |
| 3855 | const VkSwapchainCreateInfoKHR *pCreateInfos, |
| 3856 | const VkAllocationCallbacks *pAllocator, |
| 3857 | VkSwapchainKHR *pSwapchains, VkResult result) { |
| 3858 | if (pCreateInfos) { |
| 3859 | for (uint32_t i = 0; i < swapchainCount; i++) { |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3860 | auto surface_state = GetShared<SURFACE_STATE>(pCreateInfos[i].surface); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3861 | auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain); |
Jeremy Gebben | 5a542f5 | 2021-07-21 15:25:52 -0600 | [diff] [blame] | 3862 | RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state), old_swapchain_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 3868 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3869 | auto fence_state = GetFenceState(fence); |
| 3870 | if (fence_state && fence_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3871 | // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary |
| 3872 | // import |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3873 | fence_state->state = FENCE_INFLIGHT; |
| 3874 | fence_state->signaler.first = VK_NULL_HANDLE; // ANI isn't on a queue, so this can't participate in a completion proof. |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3875 | } |
| 3876 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3877 | auto semaphore_state = GetSemaphoreState(semaphore); |
| 3878 | if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3879 | // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a |
| 3880 | // temporary import |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3881 | semaphore_state->signaled = true; |
| 3882 | semaphore_state->signaler.first = VK_NULL_HANDLE; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | // Mark the image as acquired. |
| 3886 | auto swapchain_data = GetSwapchainState(swapchain); |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 3887 | if (swapchain_data) { |
| 3888 | swapchain_data->AcquireImage(*pImageIndex); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, |
| 3893 | VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex, |
| 3894 | VkResult result) { |
| 3895 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 3896 | RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex); |
| 3897 | } |
| 3898 | |
| 3899 | void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo, |
| 3900 | uint32_t *pImageIndex, VkResult result) { |
| 3901 | if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return; |
| 3902 | RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore, |
| 3903 | pAcquireInfo->fence, pImageIndex); |
| 3904 | } |
| 3905 | |
| 3906 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 3907 | VkPhysicalDevice *pPhysicalDevices, VkResult result) { |
| 3908 | if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) { |
| 3909 | for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { |
| 3910 | auto &phys_device_state = physical_device_map[pPhysicalDevices[i]]; |
| 3911 | phys_device_state.phys_device = pPhysicalDevices[i]; |
| 3912 | // Init actual features for each physical device |
| 3913 | DispatchGetPhysicalDeviceFeatures(pPhysicalDevices[i], &phys_device_state.features2.features); |
| 3914 | } |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | // Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version |
| 3919 | static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3920 | VkQueueFamilyProperties2 *pQueueFamilyProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3921 | pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count); |
| 3922 | |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 3923 | if (pQueueFamilyProperties) { // Save queue family properties |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3924 | pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count)); |
| 3925 | for (uint32_t i = 0; i < count; ++i) { |
| 3926 | pd_state->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties; |
| 3927 | } |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 3932 | uint32_t *pQueueFamilyPropertyCount, |
| 3933 | VkQueueFamilyProperties *pQueueFamilyProperties) { |
| 3934 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 3935 | assert(physical_device_state); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3936 | VkQueueFamilyProperties2 *pqfp = nullptr; |
| 3937 | std::vector<VkQueueFamilyProperties2> qfp; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3938 | qfp.resize(*pQueueFamilyPropertyCount); |
| 3939 | if (pQueueFamilyProperties) { |
| 3940 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) { |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 3941 | qfp[i] = LvlInitStruct<VkQueueFamilyProperties2>(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3942 | qfp[i].queueFamilyProperties = pQueueFamilyProperties[i]; |
| 3943 | } |
| 3944 | pqfp = qfp.data(); |
| 3945 | } |
| 3946 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, pqfp); |
| 3947 | } |
| 3948 | |
| 3949 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3950 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3951 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 3952 | assert(physical_device_state); |
| 3953 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 3954 | pQueueFamilyProperties); |
| 3955 | } |
| 3956 | |
| 3957 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3958 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3959 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 3960 | assert(physical_device_state); |
| 3961 | StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, |
| 3962 | pQueueFamilyProperties); |
| 3963 | } |
| 3964 | void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, |
| 3965 | const VkAllocationCallbacks *pAllocator) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3966 | if (!surface) return; |
| 3967 | auto surface_state = GetSurfaceState(surface); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3968 | surface_state->Destroy(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3969 | surface_map.erase(surface); |
| 3970 | } |
| 3971 | |
| 3972 | void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 3973 | surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance, |
| 3977 | const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, |
| 3978 | const VkAllocationCallbacks *pAllocator, |
| 3979 | VkSurfaceKHR *pSurface, VkResult result) { |
| 3980 | if (VK_SUCCESS != result) return; |
| 3981 | RecordVulkanSurface(pSurface); |
| 3982 | } |
| 3983 | |
| 3984 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 3985 | void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance, |
| 3986 | const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, |
| 3987 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 3988 | VkResult result) { |
| 3989 | if (VK_SUCCESS != result) return; |
| 3990 | RecordVulkanSurface(pSurface); |
| 3991 | } |
| 3992 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 3993 | |
| 3994 | #ifdef VK_USE_PLATFORM_IOS_MVK |
| 3995 | void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo, |
| 3996 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 3997 | VkResult result) { |
| 3998 | if (VK_SUCCESS != result) return; |
| 3999 | RecordVulkanSurface(pSurface); |
| 4000 | } |
| 4001 | #endif // VK_USE_PLATFORM_IOS_MVK |
| 4002 | |
| 4003 | #ifdef VK_USE_PLATFORM_MACOS_MVK |
| 4004 | void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance, |
| 4005 | const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, |
| 4006 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4007 | VkResult result) { |
| 4008 | if (VK_SUCCESS != result) return; |
| 4009 | RecordVulkanSurface(pSurface); |
| 4010 | } |
| 4011 | #endif // VK_USE_PLATFORM_MACOS_MVK |
| 4012 | |
Jeremy Kniager | f33a67c | 2019-12-09 09:44:39 -0700 | [diff] [blame] | 4013 | #ifdef VK_USE_PLATFORM_METAL_EXT |
| 4014 | void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance, |
| 4015 | const VkMetalSurfaceCreateInfoEXT *pCreateInfo, |
| 4016 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4017 | VkResult result) { |
| 4018 | if (VK_SUCCESS != result) return; |
| 4019 | RecordVulkanSurface(pSurface); |
| 4020 | } |
| 4021 | #endif // VK_USE_PLATFORM_METAL_EXT |
| 4022 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4023 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 4024 | void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance, |
| 4025 | const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, |
| 4026 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4027 | VkResult result) { |
| 4028 | if (VK_SUCCESS != result) return; |
| 4029 | RecordVulkanSurface(pSurface); |
| 4030 | } |
| 4031 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 4032 | |
| 4033 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 4034 | void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance, |
| 4035 | const VkWin32SurfaceCreateInfoKHR *pCreateInfo, |
| 4036 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4037 | VkResult result) { |
| 4038 | if (VK_SUCCESS != result) return; |
| 4039 | RecordVulkanSurface(pSurface); |
| 4040 | } |
| 4041 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 4042 | |
| 4043 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 4044 | void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, |
| 4045 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4046 | VkResult result) { |
| 4047 | if (VK_SUCCESS != result) return; |
| 4048 | RecordVulkanSurface(pSurface); |
| 4049 | } |
| 4050 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 4051 | |
| 4052 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 4053 | void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, |
| 4054 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4055 | VkResult result) { |
| 4056 | if (VK_SUCCESS != result) return; |
| 4057 | RecordVulkanSurface(pSurface); |
| 4058 | } |
| 4059 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 4060 | |
Niklas Haas | 8b84af1 | 2020-04-19 22:20:11 +0200 | [diff] [blame] | 4061 | void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance, |
| 4062 | const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, |
| 4063 | const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface, |
| 4064 | VkResult result) { |
| 4065 | if (VK_SUCCESS != result) return; |
| 4066 | RecordVulkanSurface(pSurface); |
| 4067 | } |
| 4068 | |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 4069 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 4070 | VkPhysicalDeviceFeatures *pFeatures) { |
| 4071 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Yilong Li | 358152a | 2020-07-08 02:16:45 -0700 | [diff] [blame] | 4072 | // Reset the features2 safe struct before setting up the features field. |
| 4073 | physical_device_state->features2 = safe_VkPhysicalDeviceFeatures2(); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 4074 | physical_device_state->features2.features = *pFeatures; |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 4078 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 4079 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 4080 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 4084 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 4085 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
Cort | ffba264 | 2019-09-20 22:09:41 +0200 | [diff] [blame] | 4086 | physical_device_state->features2.initialize(pFeatures); |
Cort | 23cf228 | 2019-09-20 18:58:18 +0200 | [diff] [blame] | 4087 | } |
| 4088 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4089 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, |
| 4090 | VkSurfaceKHR surface, |
| 4091 | VkSurfaceCapabilitiesKHR *pSurfaceCapabilities, |
| 4092 | VkResult result) { |
| 4093 | if (VK_SUCCESS != result) return; |
| 4094 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4095 | physical_device_state->surfaceCapabilities = *pSurfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4096 | |
| 4097 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 4098 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR( |
| 4102 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 4103 | VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) { |
| 4104 | if (VK_SUCCESS != result) return; |
| 4105 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4106 | physical_device_state->surfaceCapabilities = pSurfaceCapabilities->surfaceCapabilities; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4107 | |
| 4108 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 4109 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4110 | } |
| 4111 | |
| 4112 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, |
| 4113 | VkSurfaceKHR surface, |
| 4114 | VkSurfaceCapabilities2EXT *pSurfaceCapabilities, |
| 4115 | VkResult result) { |
| 4116 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4117 | physical_device_state->surfaceCapabilities.minImageCount = pSurfaceCapabilities->minImageCount; |
| 4118 | physical_device_state->surfaceCapabilities.maxImageCount = pSurfaceCapabilities->maxImageCount; |
| 4119 | physical_device_state->surfaceCapabilities.currentExtent = pSurfaceCapabilities->currentExtent; |
| 4120 | physical_device_state->surfaceCapabilities.minImageExtent = pSurfaceCapabilities->minImageExtent; |
| 4121 | physical_device_state->surfaceCapabilities.maxImageExtent = pSurfaceCapabilities->maxImageExtent; |
| 4122 | physical_device_state->surfaceCapabilities.maxImageArrayLayers = pSurfaceCapabilities->maxImageArrayLayers; |
| 4123 | physical_device_state->surfaceCapabilities.supportedTransforms = pSurfaceCapabilities->supportedTransforms; |
| 4124 | physical_device_state->surfaceCapabilities.currentTransform = pSurfaceCapabilities->currentTransform; |
| 4125 | physical_device_state->surfaceCapabilities.supportedCompositeAlpha = pSurfaceCapabilities->supportedCompositeAlpha; |
| 4126 | physical_device_state->surfaceCapabilities.supportedUsageFlags = pSurfaceCapabilities->supportedUsageFlags; |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4127 | |
| 4128 | // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first |
| 4129 | physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, |
| 4133 | uint32_t queueFamilyIndex, VkSurfaceKHR surface, |
| 4134 | VkBool32 *pSupported, VkResult result) { |
| 4135 | if (VK_SUCCESS != result) return; |
| 4136 | auto surface_state = GetSurfaceState(surface); |
| 4137 | surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE); |
| 4138 | } |
| 4139 | |
| 4140 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, |
| 4141 | VkSurfaceKHR surface, |
| 4142 | uint32_t *pPresentModeCount, |
| 4143 | VkPresentModeKHR *pPresentModes, |
| 4144 | VkResult result) { |
| 4145 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4146 | |
| 4147 | // TODO: This isn't quite right -- available modes may differ by surface AND physical device. |
| 4148 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4149 | |
| 4150 | if (*pPresentModeCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4151 | if (*pPresentModeCount > physical_device_state->present_modes.size()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4152 | physical_device_state->present_modes.resize(*pPresentModeCount); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4153 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4154 | } |
| 4155 | if (pPresentModes) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4156 | for (uint32_t i = 0; i < *pPresentModeCount; i++) { |
| 4157 | physical_device_state->present_modes[i] = pPresentModes[i]; |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, |
| 4163 | uint32_t *pSurfaceFormatCount, |
| 4164 | VkSurfaceFormatKHR *pSurfaceFormats, |
| 4165 | VkResult result) { |
| 4166 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4167 | |
| 4168 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4169 | |
| 4170 | if (*pSurfaceFormatCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4171 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4172 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4173 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4174 | } |
| 4175 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4176 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
| 4177 | physical_device_state->surface_formats[i] = pSurfaceFormats[i]; |
| 4178 | } |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, |
| 4183 | const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, |
| 4184 | uint32_t *pSurfaceFormatCount, |
| 4185 | VkSurfaceFormat2KHR *pSurfaceFormats, |
| 4186 | VkResult result) { |
| 4187 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4188 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4189 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4190 | if (*pSurfaceFormatCount) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4191 | if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) { |
| 4192 | physical_device_state->surface_formats.resize(*pSurfaceFormatCount); |
| 4193 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4194 | } |
| 4195 | if (pSurfaceFormats) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4196 | for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4197 | physical_device_state->surface_formats[i] = pSurfaceFormats[i].surfaceFormat; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4198 | } |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 4203 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 4204 | BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 4205 | } |
| 4206 | |
| 4207 | void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) { |
| 4208 | EndCmdDebugUtilsLabel(report_data, commandBuffer); |
| 4209 | } |
| 4210 | |
| 4211 | void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, |
| 4212 | const VkDebugUtilsLabelEXT *pLabelInfo) { |
| 4213 | InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo); |
| 4214 | |
| 4215 | // Squirrel away an easily accessible copy. |
| 4216 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4217 | cb_state->debug_label = LoggingLabel(pLabelInfo); |
| 4218 | } |
| 4219 | |
| 4220 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4221 | uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4222 | if (NULL != pPhysicalDeviceGroupProperties) { |
| 4223 | for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { |
| 4224 | for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) { |
| 4225 | VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j]; |
| 4226 | auto &phys_device_state = physical_device_map[cur_phys_dev]; |
| 4227 | phys_device_state.phys_device = cur_phys_dev; |
| 4228 | // Init actual features for each physical device |
| 4229 | DispatchGetPhysicalDeviceFeatures(cur_phys_dev, &phys_device_state.features2.features); |
| 4230 | } |
| 4231 | } |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4236 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4237 | VkResult result) { |
| 4238 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4239 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 4240 | } |
| 4241 | |
| 4242 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4243 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4244 | VkResult result) { |
| 4245 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4246 | RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties); |
| 4247 | } |
| 4248 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4249 | void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice, |
| 4250 | uint32_t queueFamilyIndex, |
| 4251 | uint32_t *pCounterCount, |
| 4252 | VkPerformanceCounterKHR *pCounters) { |
| 4253 | if (NULL == pCounters) return; |
| 4254 | |
| 4255 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 4256 | assert(physical_device_state); |
| 4257 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4258 | std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS()); |
| 4259 | queue_family_counters->counters.resize(*pCounterCount); |
| 4260 | for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i]; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4261 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4262 | physical_device_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters); |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( |
| 4266 | VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters, |
| 4267 | VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) { |
| 4268 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4269 | RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters); |
| 4270 | } |
| 4271 | |
| 4272 | void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo, |
| 4273 | VkResult result) { |
| 4274 | if (result == VK_SUCCESS) performance_lock_acquired = true; |
| 4275 | } |
| 4276 | |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4277 | void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) { |
| 4278 | performance_lock_acquired = false; |
| 4279 | for (auto &cmd_buffer : commandBufferMap) { |
| 4280 | cmd_buffer.second->performance_lock_released = true; |
| 4281 | } |
| 4282 | } |
| 4283 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4284 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4285 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4286 | const VkAllocationCallbacks *pAllocator) { |
| 4287 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4288 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 4289 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4290 | desc_template_map.erase(descriptorUpdateTemplate); |
| 4291 | } |
| 4292 | |
| 4293 | void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4294 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4295 | const VkAllocationCallbacks *pAllocator) { |
| 4296 | if (!descriptorUpdateTemplate) return; |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4297 | auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 4298 | template_state->destroyed = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4299 | desc_template_map.erase(descriptorUpdateTemplate); |
| 4300 | } |
| 4301 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4302 | void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, |
| 4303 | VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4304 | safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4305 | auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4306 | desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state); |
| 4307 | } |
| 4308 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4309 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device, |
| 4310 | const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, |
| 4311 | const VkAllocationCallbacks *pAllocator, |
| 4312 | VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, |
| 4313 | VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4314 | if (VK_SUCCESS != result) return; |
| 4315 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 4316 | } |
| 4317 | |
| 4318 | void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR( |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4319 | VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 4320 | VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4321 | if (VK_SUCCESS != result) return; |
| 4322 | RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate); |
| 4323 | } |
| 4324 | |
| 4325 | void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4326 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4327 | const void *pData) { |
| 4328 | auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate); |
| 4329 | if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) { |
| 4330 | assert(0); |
| 4331 | } else { |
| 4332 | const TEMPLATE_STATE *template_state = template_map_entry->second.get(); |
| 4333 | // TODO: Record template push descriptor updates |
| 4334 | if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) { |
| 4335 | PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData); |
| 4336 | } |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet, |
| 4341 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 4342 | const void *pData) { |
| 4343 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 4344 | } |
| 4345 | |
| 4346 | void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet, |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4347 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4348 | const void *pData) { |
| 4349 | RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData); |
| 4350 | } |
| 4351 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 4352 | void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer, |
| 4353 | VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 4354 | VkPipelineLayout layout, uint32_t set, |
| 4355 | const void *pData) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4356 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4357 | |
| 4358 | const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate); |
| 4359 | if (template_state) { |
| 4360 | auto layout_data = GetPipelineLayout(layout); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 4361 | auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4362 | const auto &template_ci = template_state->create_info; |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4363 | // Decode the template into a set of write updates |
| 4364 | cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData, |
| 4365 | dsl->GetDescriptorSetLayout()); |
| 4366 | cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data, set, |
| 4367 | static_cast<uint32_t>(decoded_template.desc_writes.size()), |
| 4368 | decoded_template.desc_writes.data()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice, |
| 4373 | uint32_t *pPropertyCount, void *pProperties) { |
| 4374 | auto physical_device_state = GetPhysicalDeviceState(physicalDevice); |
| 4375 | if (*pPropertyCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4376 | physical_device_state->display_plane_property_count = *pPropertyCount; |
| 4377 | } |
Nathaniel Cesario | 24184fe | 2020-10-06 12:46:12 -0600 | [diff] [blame] | 4378 | if (*pPropertyCount || pProperties) { |
| 4379 | physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, |
| 4384 | uint32_t *pPropertyCount, |
| 4385 | VkDisplayPlanePropertiesKHR *pProperties, |
| 4386 | VkResult result) { |
| 4387 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4388 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 4389 | } |
| 4390 | |
| 4391 | void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice, |
| 4392 | uint32_t *pPropertyCount, |
| 4393 | VkDisplayPlaneProperties2KHR *pProperties, |
| 4394 | VkResult result) { |
| 4395 | if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return; |
| 4396 | RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties); |
| 4397 | } |
| 4398 | |
| 4399 | void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4400 | uint32_t query, VkQueryControlFlags flags, uint32_t index) { |
| 4401 | QueryObject query_obj = {queryPool, query, index}; |
| 4402 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4403 | cb_state->BeginQuery(query_obj); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, |
| 4407 | uint32_t query, uint32_t index) { |
| 4408 | QueryObject query_obj = {queryPool, query, index}; |
| 4409 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4410 | cb_state->EndQuery(query_obj); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info, |
| 4414 | VkSamplerYcbcrConversion ycbcr_conversion) { |
Jeremy Gebben | f4fb2a0 | 2021-07-08 09:57:46 -0600 | [diff] [blame] | 4415 | VkFormatFeatureFlags format_features = 0; |
| 4416 | |
| 4417 | if (create_info->format != VK_FORMAT_UNDEFINED) { |
| 4418 | format_features = GetPotentialFormatFeatures(create_info->format); |
| 4419 | } else if (device_extensions.vk_android_external_memory_android_hardware_buffer) { |
| 4420 | // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features |
| 4421 | format_features = GetExternalFormatFeaturesANDROID(create_info); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4422 | } |
Jeremy Gebben | f4fb2a0 | 2021-07-08 09:57:46 -0600 | [diff] [blame] | 4423 | |
| 4424 | samplerYcbcrConversionMap[ycbcr_conversion] = |
| 4425 | std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device, |
| 4429 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 4430 | const VkAllocationCallbacks *pAllocator, |
| 4431 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 4432 | VkResult result) { |
| 4433 | if (VK_SUCCESS != result) return; |
| 4434 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 4435 | } |
| 4436 | |
| 4437 | void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device, |
| 4438 | const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, |
| 4439 | const VkAllocationCallbacks *pAllocator, |
| 4440 | VkSamplerYcbcrConversion *pYcbcrConversion, |
| 4441 | VkResult result) { |
| 4442 | if (VK_SUCCESS != result) return; |
| 4443 | RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion); |
| 4444 | } |
| 4445 | |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 4446 | void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) { |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 4447 | auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4448 | ycbcr_state->Destroy(); |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 4449 | samplerYcbcrConversionMap.erase(ycbcr_conversion); |
| 4450 | } |
| 4451 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4452 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, |
| 4453 | const VkAllocationCallbacks *pAllocator) { |
| 4454 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 4455 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device, |
| 4459 | VkSamplerYcbcrConversion ycbcrConversion, |
| 4460 | const VkAllocationCallbacks *pAllocator) { |
| 4461 | if (!ycbcrConversion) return; |
sfricke-samsung | be3584f | 2020-04-22 14:58:06 -0700 | [diff] [blame] | 4462 | RecordDestroySamplerYcbcrConversionState(ycbcrConversion); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4463 | } |
| 4464 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4465 | void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 4466 | uint32_t queryCount) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4467 | // Do nothing if the feature is not enabled. |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 4468 | if (!enabled_features.core12.hostQueryReset) return; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4469 | |
| 4470 | // Do nothing if the query pool has been destroyed. |
| 4471 | auto query_pool_state = GetQueryPoolState(queryPool); |
| 4472 | if (!query_pool_state) return; |
| 4473 | |
| 4474 | // Reset the state of existing entries. |
| 4475 | QueryObject query_obj{queryPool, 0}; |
| 4476 | const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery); |
| 4477 | for (uint32_t i = 0; i < max_query_count; ++i) { |
| 4478 | query_obj.query = firstQuery + i; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4479 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4480 | if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4481 | for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) { |
| 4482 | query_obj.perf_pass = pass_index; |
Lionel Landwerlin | 7dc796b | 2020-02-18 18:17:10 +0200 | [diff] [blame] | 4483 | queryToStateMap[query_obj] = QUERYSTATE_RESET; |
Lionel Landwerlin | c742091 | 2019-05-23 00:33:42 +0100 | [diff] [blame] | 4484 | } |
| 4485 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4486 | } |
| 4487 | } |
| 4488 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4489 | void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 4490 | uint32_t queryCount) { |
| 4491 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 4492 | } |
| 4493 | |
| 4494 | void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, |
| 4495 | uint32_t queryCount) { |
| 4496 | RecordResetQueryPool(device, queryPool, firstQuery, queryCount); |
| 4497 | } |
| 4498 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4499 | void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet, |
| 4500 | const TEMPLATE_STATE *template_state, const void *pData) { |
| 4501 | // Translate the templated update into a normal update for validation... |
| 4502 | cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData); |
| 4503 | cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()), |
| 4504 | decoded_update.desc_writes.data(), 0, NULL); |
| 4505 | } |
| 4506 | |
| 4507 | // Update the common AllocateDescriptorSetsData |
| 4508 | void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 4509 | cvdescriptorset::AllocateDescriptorSetsData *ds_data) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4510 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 4511 | auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4512 | if (layout) { |
| 4513 | ds_data->layout_nodes[i] = layout; |
| 4514 | // Count total descriptors required per type |
| 4515 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 4516 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 4517 | uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType); |
| 4518 | ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount; |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4519 | } |
| 4520 | } |
| 4521 | // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call |
| 4522 | } |
| 4523 | } |
| 4524 | |
| 4525 | // Decrement allocated sets from the pool and insert new sets into set_map |
| 4526 | void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 4527 | const VkDescriptorSet *descriptor_sets, |
| 4528 | const cvdescriptorset::AllocateDescriptorSetsData *ds_data) { |
| 4529 | auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get(); |
| 4530 | // Account for sets and individual descriptors allocated from pool |
| 4531 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
| 4532 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
| 4533 | pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first); |
| 4534 | } |
| 4535 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 4536 | const auto *variable_count_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(p_alloc_info->pNext); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4537 | bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount; |
| 4538 | |
| 4539 | // Create tracking object for each descriptor set; insert into global map and the pool's set. |
| 4540 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 4541 | uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0; |
| 4542 | |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 4543 | 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] | 4544 | variable_count, this); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4545 | pool_state->sets.insert(new_ds.get()); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4546 | setMap[descriptor_sets[i]] = std::move(new_ds); |
| 4547 | } |
| 4548 | } |
| 4549 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4550 | void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 4551 | uint32_t firstVertex, uint32_t firstInstance) { |
| 4552 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4553 | cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4554 | } |
| 4555 | |
Tony-LunarG | 745150c | 2021-07-02 15:07:31 -0600 | [diff] [blame] | 4556 | void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 4557 | const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount, |
| 4558 | uint32_t firstInstance, uint32_t stride) { |
| 4559 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4560 | cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMultiEXT()"); |
Tony-LunarG | 745150c | 2021-07-02 15:07:31 -0600 | [diff] [blame] | 4561 | } |
| 4562 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4563 | void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, |
| 4564 | uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, |
| 4565 | uint32_t firstInstance) { |
| 4566 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4567 | cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4568 | } |
| 4569 | |
Tony-LunarG | 745150c | 2021-07-02 15:07:31 -0600 | [diff] [blame] | 4570 | void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 4571 | const VkMultiDrawIndexedInfoEXT *pIndexInfo, |
| 4572 | uint32_t instanceCount, uint32_t firstInstance, uint32_t stride, |
| 4573 | const int32_t *pVertexOffset) { |
| 4574 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4575 | cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMultiIndexedEXT()"); |
Tony-LunarG | 745150c | 2021-07-02 15:07:31 -0600 | [diff] [blame] | 4576 | } |
| 4577 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4578 | void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4579 | uint32_t count, uint32_t stride) { |
| 4580 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4581 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4582 | cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect()"); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4583 | if (!disabled[command_buffer_state]) { |
| 4584 | cb_state->AddChild(buffer_state); |
| 4585 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4589 | VkDeviceSize offset, uint32_t count, uint32_t stride) { |
| 4590 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4591 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4592 | cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect()"); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4593 | if (!disabled[command_buffer_state]) { |
| 4594 | cb_state->AddChild(buffer_state); |
| 4595 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
| 4599 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4600 | cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4604 | VkDeviceSize offset) { |
| 4605 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4606 | cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect()"); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4607 | if (!disabled[command_buffer_state]) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4608 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4609 | cb_state->AddChild(buffer_state); |
| 4610 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4611 | } |
| 4612 | |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4613 | void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4614 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 4615 | uint32_t stride, const char *function) { |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4616 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4617 | cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4618 | if (!disabled[command_buffer_state]) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4619 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 4620 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4621 | cb_state->AddChild(buffer_state); |
| 4622 | cb_state->AddChild(count_buffer_state); |
| 4623 | } |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4626 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4627 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4628 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4629 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 4630 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4631 | "vkCmdDrawIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4635 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 4636 | uint32_t maxDrawCount, uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 4637 | RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4638 | "vkCmdDrawIndirectCount()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 4642 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 4643 | uint32_t maxDrawCount, uint32_t stride, const char *function) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4644 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4645 | cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4646 | if (!disabled[command_buffer_state]) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4647 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 4648 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4649 | cb_state->AddChild(buffer_state); |
| 4650 | cb_state->AddChild(count_buffer_state); |
| 4651 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4655 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4656 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4657 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 4658 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4659 | "vkCmdDrawIndexedIndirectCountKHR()"); |
Tony-LunarG | 977448c | 2019-12-02 14:52:02 -0700 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4663 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4664 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4665 | uint32_t stride) { |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 4666 | RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride, |
| 4667 | "vkCmdDrawIndexedIndirectCount()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, |
| 4671 | uint32_t firstTask) { |
| 4672 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4673 | cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMeshTasksNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4677 | VkDeviceSize offset, uint32_t drawCount, uint32_t stride) { |
| 4678 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4679 | cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 4680 | "vkCmdDrawMeshTasksIndirectNV()"); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4681 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4682 | if (!disabled[command_buffer_state] && buffer_state) { |
| 4683 | cb_state->AddChild(buffer_state); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, |
| 4688 | VkDeviceSize offset, VkBuffer countBuffer, |
| 4689 | VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 4690 | uint32_t stride) { |
| 4691 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4692 | cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 4693 | "vkCmdDrawMeshTasksIndirectCountNV()"); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4694 | if (!disabled[command_buffer_state]) { |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4695 | BUFFER_STATE *buffer_state = GetBufferState(buffer); |
| 4696 | BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4697 | if (buffer_state) { |
| 4698 | cb_state->AddChild(buffer_state); |
| 4699 | } |
| 4700 | if (count_buffer_state) { |
| 4701 | cb_state->AddChild(count_buffer_state); |
| 4702 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4703 | } |
| 4704 | } |
| 4705 | |
Jeremy Gebben | 252f60c | 2021-07-15 14:54:30 -0600 | [diff] [blame] | 4706 | void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer, |
| 4707 | VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer, |
| 4708 | VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride, |
| 4709 | VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset, |
| 4710 | VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer, |
| 4711 | VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride, |
| 4712 | uint32_t width, uint32_t height, uint32_t depth) { |
| 4713 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4714 | cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV, "vkCmdTraceRaysNV()"); |
Jeremy Gebben | 252f60c | 2021-07-15 14:54:30 -0600 | [diff] [blame] | 4715 | cb_state->hasTraceRaysCmd = true; |
| 4716 | } |
| 4717 | |
| 4718 | |
| 4719 | void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer, |
| 4720 | const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable, |
| 4721 | const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable, |
| 4722 | const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, |
| 4723 | const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width, |
| 4724 | uint32_t height, uint32_t depth) { |
| 4725 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4726 | cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, "vkCmdTraceRaysKHR()"); |
Jeremy Gebben | 252f60c | 2021-07-15 14:54:30 -0600 | [diff] [blame] | 4727 | cb_state->hasTraceRaysCmd = true; |
| 4728 | } |
| 4729 | |
| 4730 | void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, |
| 4731 | const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable, |
| 4732 | const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable, |
| 4733 | const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, |
| 4734 | const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, |
| 4735 | VkDeviceAddress indirectDeviceAddress) { |
| 4736 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
Jeremy Gebben | 1ec8933 | 2021-08-05 13:51:49 -0600 | [diff] [blame] | 4737 | cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, |
Jeremy Gebben | 252f60c | 2021-07-15 14:54:30 -0600 | [diff] [blame] | 4738 | "vkCmdTraceRaysIndirectKHR()"); |
| 4739 | cb_state->hasTraceRaysCmd = true; |
| 4740 | } |
| 4741 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4742 | void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 4743 | const VkAllocationCallbacks *pAllocator, |
| 4744 | VkShaderModule *pShaderModule, VkResult result, |
| 4745 | void *csm_state_data) { |
| 4746 | if (VK_SUCCESS != result) return; |
| 4747 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
| 4748 | |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 4749 | 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] | 4750 | bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber); |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 4751 | auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment, |
| 4752 | csm_state->unique_shader_id) |
| 4753 | : std::make_shared<SHADER_MODULE_STATE>(); |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 4754 | new_shader_module->SetPushConstantUsedInShader(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4755 | shaderModuleMap[*pShaderModule] = std::move(new_shader_module); |
| 4756 | } |
| 4757 | |
| 4758 | void ValidationStateTracker::RecordPipelineShaderStage(VkPipelineShaderStageCreateInfo const *pStage, PIPELINE_STATE *pipeline, |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 4759 | PipelineStageState *stage_state) const { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4760 | // Validation shouldn't rely on anything in stage state being valid if the spirv isn't |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 4761 | stage_state->entry_point_name = pStage->pName; |
| 4762 | stage_state->shader_state = GetShared<SHADER_MODULE_STATE>(pStage->module); |
| 4763 | auto module = stage_state->shader_state.get(); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4764 | if (!module->has_valid_spirv) return; |
| 4765 | |
| 4766 | // Validation shouldn't rely on anything in stage state being valid if the entrypoint isn't present |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 4767 | auto entrypoint = module->FindEntrypoint(pStage->pName, pStage->stage); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4768 | if (entrypoint == module->end()) return; |
| 4769 | |
locke-lunarg | 654e369 | 2020-06-04 17:19:15 -0600 | [diff] [blame] | 4770 | stage_state->stage_flag = pStage->stage; |
| 4771 | |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4772 | // Mark accessible ids |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 4773 | stage_state->accessible_ids = module->MarkAccessibleIds(entrypoint); |
| 4774 | module->ProcessExecutionModes(entrypoint, pipeline); |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4775 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 4776 | stage_state->descriptor_uses = module->CollectInterfaceByDescriptorSlot( |
| 4777 | 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] | 4778 | // Capture descriptor uses for the pipeline |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 4779 | for (const auto &use : stage_state->descriptor_uses) { |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4780 | // While validating shaders capture which slots are used by the pipeline |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 4781 | const uint32_t slot = use.first.first; |
locke-lunarg | 351c9d8 | 2020-10-23 14:43:21 -0600 | [diff] [blame] | 4782 | pipeline->active_slots[slot][use.first.second].is_writable |= use.second.is_writable; |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 4783 | auto &reqs = pipeline->active_slots[slot][use.first.second].reqs; |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 4784 | reqs = descriptor_req(reqs | module->DescriptorTypeToReqs(use.second.type_id)); |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 4785 | 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] | 4786 | 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] | 4787 | 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] | 4788 | |
John Zulauf | 649edd5 | 2019-10-02 14:39:41 -0600 | [diff] [blame] | 4789 | pipeline->max_active_slot = std::max(pipeline->max_active_slot, slot); |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 4790 | if (use.second.samplers_used_by_image.size()) { |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 4791 | auto &samplers_used_by_image = pipeline->active_slots[slot][use.first.second].samplers_used_by_image; |
| 4792 | if (use.second.samplers_used_by_image.size() > samplers_used_by_image.size()) { |
| 4793 | samplers_used_by_image.resize(use.second.samplers_used_by_image.size()); |
| 4794 | } |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 4795 | uint32_t image_index = 0; |
| 4796 | for (const auto &samplers : use.second.samplers_used_by_image) { |
| 4797 | for (const auto &sampler : samplers) { |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 4798 | samplers_used_by_image[image_index].emplace(sampler, nullptr); |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 4799 | } |
| 4800 | ++image_index; |
| 4801 | } |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 4802 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4803 | } |
locke-lunarg | 7848683 | 2020-09-09 19:39:42 -0600 | [diff] [blame] | 4804 | |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 4805 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 4806 | pipeline->fragmentShader_writable_output_location_list = module->CollectWritableOutputLocationinFS(*pStage); |
locke-lunarg | 96dc963 | 2020-06-10 17:22:18 -0600 | [diff] [blame] | 4807 | } |
locke-lunarg | d556cc3 | 2019-09-17 01:21:23 -0600 | [diff] [blame] | 4808 | } |
| 4809 | |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4810 | void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, |
| 4811 | uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages, |
| 4812 | VkResult result) { |
| 4813 | if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return; |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 4814 | auto swapchain_state = GetShared<SWAPCHAIN_NODE>(swapchain); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4815 | |
| 4816 | if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount); |
| 4817 | |
| 4818 | if (pSwapchainImages) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4819 | for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) { |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 4820 | SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i]; |
John Zulauf | faa7a52 | 2021-03-05 12:22:45 -0700 | [diff] [blame] | 4821 | if (swapchain_image.image_state) continue; // Already retrieved this. |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4822 | |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 4823 | auto format_features = |
| 4824 | GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format, |
| 4825 | swapchain_state->image_create_info.tiling); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4826 | |
Jeremy Gebben | bcba6d3 | 2021-07-16 11:41:41 -0600 | [diff] [blame] | 4827 | auto image_state = std::make_shared<IMAGE_STATE>(device, pSwapchainImages[i], swapchain_state->image_create_info.ptr(), |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 4828 | swapchain, i, format_features); |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 4829 | if (!swapchain_image.fake_base_address) { |
| 4830 | auto size = image_state->fragment_encoder->TotalSize(); |
| 4831 | swapchain_image.fake_base_address = fake_memory.Alloc(size); |
John Zulauf | 29d0053 | 2021-03-04 13:28:54 -0700 | [diff] [blame] | 4832 | } |
| 4833 | |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 4834 | image_state->SetSwapchain(swapchain_state, i); |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 4835 | swapchain_image.image_state = image_state.get(); |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 4836 | imageMap[pSwapchainImages[i]] = std::move(image_state); |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | if (*pSwapchainImageCount) { |
John Zulauf | 22b0fbe | 2019-10-15 06:26:16 -0600 | [diff] [blame] | 4841 | swapchain_state->get_swapchain_image_count = *pSwapchainImageCount; |
| 4842 | } |
| 4843 | } |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 4844 | |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 4845 | void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, |
| 4846 | const VkCopyAccelerationStructureInfoKHR *pInfo) { |
| 4847 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4848 | if (cb_state) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 4849 | ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src); |
| 4850 | ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst); |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 4851 | if (dst_as_state != nullptr && src_as_state != nullptr) { |
| 4852 | dst_as_state->built = true; |
| 4853 | dst_as_state->build_info_khr = src_as_state->build_info_khr; |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4854 | if (!disabled[command_buffer_state]) { |
| 4855 | cb_state->AddChild(dst_as_state); |
| 4856 | cb_state->AddChild(src_as_state); |
| 4857 | } |
sourav parmar | 35e7a00 | 2020-06-09 17:58:44 -0700 | [diff] [blame] | 4858 | } |
| 4859 | } |
| 4860 | } |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4861 | |
| 4862 | void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) { |
| 4863 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4864 | cb_state->status |= CBSTATUS_CULL_MODE_SET; |
| 4865 | cb_state->static_status &= ~CBSTATUS_CULL_MODE_SET; |
| 4866 | } |
| 4867 | |
| 4868 | void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) { |
| 4869 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4870 | cb_state->status |= CBSTATUS_FRONT_FACE_SET; |
| 4871 | cb_state->static_status &= ~CBSTATUS_FRONT_FACE_SET; |
| 4872 | } |
| 4873 | |
| 4874 | void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer, |
| 4875 | VkPrimitiveTopology primitiveTopology) { |
| 4876 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4877 | cb_state->primitiveTopology = primitiveTopology; |
| 4878 | cb_state->status |= CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 4879 | cb_state->static_status &= ~CBSTATUS_PRIMITIVE_TOPOLOGY_SET; |
| 4880 | } |
| 4881 | |
| 4882 | void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount, |
| 4883 | const VkViewport *pViewports) { |
| 4884 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 4885 | uint32_t bits = (1u << viewportCount) - 1u; |
| 4886 | cb_state->viewportWithCountMask |= bits; |
| 4887 | cb_state->trashedViewportMask &= ~bits; |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 4888 | cb_state->viewportWithCountCount = viewportCount; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 4889 | cb_state->trashedViewportCount = false; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4890 | cb_state->status |= CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
| 4891 | cb_state->static_status &= ~CBSTATUS_VIEWPORT_WITH_COUNT_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 4892 | |
| 4893 | cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size())); |
| 4894 | for (size_t i = 0; i < viewportCount; ++i) { |
| 4895 | cb_state->dynamicViewports[i] = pViewports[i]; |
| 4896 | } |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount, |
| 4900 | const VkRect2D *pScissors) { |
| 4901 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 4902 | uint32_t bits = (1u << scissorCount) - 1u; |
| 4903 | cb_state->scissorWithCountMask |= bits; |
| 4904 | cb_state->trashedScissorMask &= ~bits; |
| 4905 | cb_state->scissorWithCountCount = scissorCount; |
| 4906 | cb_state->trashedScissorCount = false; |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4907 | cb_state->status |= CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 4908 | cb_state->static_status &= ~CBSTATUS_SCISSOR_WITH_COUNT_SET; |
| 4909 | } |
| 4910 | |
| 4911 | void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding, |
| 4912 | uint32_t bindingCount, const VkBuffer *pBuffers, |
| 4913 | const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes, |
| 4914 | const VkDeviceSize *pStrides) { |
| 4915 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4916 | if (pStrides) { |
| 4917 | cb_state->status |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 4918 | cb_state->static_status &= ~CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET; |
| 4919 | } |
| 4920 | |
| 4921 | uint32_t end = firstBinding + bindingCount; |
| 4922 | if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) { |
| 4923 | cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end); |
| 4924 | } |
| 4925 | |
| 4926 | for (uint32_t i = 0; i < bindingCount; ++i) { |
| 4927 | auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding]; |
locke-lunarg | 1ae57d6 | 2020-11-18 10:49:19 -0700 | [diff] [blame] | 4928 | vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4929 | vertex_buffer_binding.offset = pOffsets[i]; |
| 4930 | vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE; |
| 4931 | vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0; |
| 4932 | // Add binding for this vertex buffer to this commandbuffer |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 4933 | if (!disabled[command_buffer_state] && pBuffers[i]) { |
| 4934 | cb_state->AddChild(vertex_buffer_binding.buffer_state.get()); |
Piers Daniell | 39842ee | 2020-07-10 16:42:33 -0600 | [diff] [blame] | 4935 | } |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) { |
| 4940 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4941 | cb_state->status |= CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 4942 | cb_state->static_status &= ~CBSTATUS_DEPTH_TEST_ENABLE_SET; |
| 4943 | } |
| 4944 | |
| 4945 | void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) { |
| 4946 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4947 | cb_state->status |= CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 4948 | cb_state->static_status &= ~CBSTATUS_DEPTH_WRITE_ENABLE_SET; |
| 4949 | } |
| 4950 | |
| 4951 | void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) { |
| 4952 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4953 | cb_state->status |= CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 4954 | cb_state->static_status &= ~CBSTATUS_DEPTH_COMPARE_OP_SET; |
| 4955 | } |
| 4956 | |
| 4957 | void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer, |
| 4958 | VkBool32 depthBoundsTestEnable) { |
| 4959 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4960 | cb_state->status |= CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 4961 | cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET; |
| 4962 | } |
| 4963 | void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) { |
| 4964 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4965 | cb_state->status |= CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 4966 | cb_state->static_status &= ~CBSTATUS_STENCIL_TEST_ENABLE_SET; |
| 4967 | } |
| 4968 | |
| 4969 | void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, |
| 4970 | VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp, |
| 4971 | VkCompareOp compareOp) { |
| 4972 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4973 | cb_state->status |= CBSTATUS_STENCIL_OP_SET; |
| 4974 | cb_state->static_status &= ~CBSTATUS_STENCIL_OP_SET; |
| 4975 | } |
locke-lunarg | 4189aa2 | 2020-10-21 00:23:48 -0600 | [diff] [blame] | 4976 | |
| 4977 | void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle, |
| 4978 | uint32_t discardRectangleCount, |
| 4979 | const VkRect2D *pDiscardRectangles) { |
| 4980 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4981 | cb_state->status |= CBSTATUS_DISCARD_RECTANGLE_SET; |
| 4982 | cb_state->static_status &= ~CBSTATUS_DISCARD_RECTANGLE_SET; |
| 4983 | } |
| 4984 | |
| 4985 | void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer, |
| 4986 | const VkSampleLocationsInfoEXT *pSampleLocationsInfo) { |
| 4987 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4988 | cb_state->status |= CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 4989 | cb_state->static_status &= ~CBSTATUS_SAMPLE_LOCATIONS_SET; |
| 4990 | } |
| 4991 | |
| 4992 | void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer, |
| 4993 | VkCoarseSampleOrderTypeNV sampleOrderType, |
| 4994 | uint32_t customSampleOrderCount, |
| 4995 | const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) { |
| 4996 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 4997 | cb_state->status |= CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 4998 | cb_state->static_status &= ~CBSTATUS_COARSE_SAMPLE_ORDER_SET; |
| 4999 | } |
Vikram Kushwaha | a57b0c3 | 2021-04-19 12:21:46 -0700 | [diff] [blame] | 5000 | |
| 5001 | void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) { |
| 5002 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5003 | cb_state->status |= CBSTATUS_PATCH_CONTROL_POINTS_SET; |
| 5004 | cb_state->static_status &= ~CBSTATUS_PATCH_CONTROL_POINTS_SET; |
| 5005 | } |
| 5006 | |
| 5007 | void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) { |
| 5008 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5009 | cb_state->status |= CBSTATUS_LOGIC_OP_SET; |
| 5010 | cb_state->static_status &= ~CBSTATUS_LOGIC_OP_SET; |
| 5011 | } |
| 5012 | |
| 5013 | void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer, |
| 5014 | VkBool32 rasterizerDiscardEnable) { |
| 5015 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5016 | cb_state->status |= CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET; |
| 5017 | cb_state->static_status &= ~CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET; |
| 5018 | } |
| 5019 | |
| 5020 | void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) { |
| 5021 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5022 | cb_state->status |= CBSTATUS_DEPTH_BIAS_ENABLE_SET; |
| 5023 | cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_ENABLE_SET; |
| 5024 | } |
| 5025 | |
| 5026 | void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer, |
| 5027 | VkBool32 primitiveRestartEnable) { |
| 5028 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5029 | cb_state->status |= CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET; |
| 5030 | cb_state->static_status &= ~CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET; |
David Zhao Akeley | 44139b1 | 2021-04-26 16:16:13 -0700 | [diff] [blame] | 5031 | } |
Piers Daniell | 924cd83 | 2021-05-18 13:48:47 -0600 | [diff] [blame] | 5032 | |
| 5033 | void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT( |
| 5034 | VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount, |
| 5035 | const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount, |
| 5036 | const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) { |
| 5037 | CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer); |
| 5038 | cb_state->status |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET | CBSTATUS_VERTEX_INPUT_SET; |
| 5039 | cb_state->static_status &= ~(CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET | CBSTATUS_VERTEX_INPUT_SET); |
| 5040 | } |
Nathaniel Cesario | 42ac6ca | 2021-06-15 17:23:05 -0600 | [diff] [blame] | 5041 | |
| 5042 | void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) { |
| 5043 | BUFFER_STATE *buffer_state = GetBufferState(pInfo->buffer); |
| 5044 | if (buffer_state) { |
| 5045 | // address is used for GPU-AV and ray tracing buffer validation |
| 5046 | buffer_state->deviceAddress = address; |
| 5047 | buffer_address_map_.emplace(address, buffer_state); |
| 5048 | } |
| 5049 | } |
| 5050 | |
| 5051 | void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo, |
| 5052 | VkDeviceAddress address) { |
| 5053 | RecordGetBufferDeviceAddress(pInfo, address); |
| 5054 | } |
| 5055 | |
| 5056 | void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo, |
| 5057 | VkDeviceAddress address) { |
| 5058 | RecordGetBufferDeviceAddress(pInfo, address); |
| 5059 | } |
| 5060 | |
| 5061 | void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo, |
| 5062 | VkDeviceAddress address) { |
| 5063 | RecordGetBufferDeviceAddress(pInfo, address); |
Nathaniel Cesario | 39152e6 | 2021-07-02 13:04:16 -0600 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info, |
| 5067 | VkSwapchainKHR swapchain) { |
Jeremy Gebben | 62c3bf4 | 2021-07-21 15:38:24 -0600 | [diff] [blame] | 5068 | return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain); |
Nathaniel Cesario | 39152e6 | 2021-07-02 13:04:16 -0600 | [diff] [blame] | 5069 | } |