blob: 69f5e1b30e4e7c629e665d580246f3967389a990 [file] [log] [blame]
sfricke-samsung486a51e2021-01-02 00:10:15 -08001/* 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 Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
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 Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
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 Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
Jeremy Gebben11af9792021-08-20 10:20:09 -060042extern template PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *, const VkRayTracingPipelineCreateInfoKHR *,
43 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&);
44extern template PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *, const VkRayTracingPipelineCreateInfoNV *,
45 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&);
46
Mark Lobodzinskib4ab6ac2020-04-02 13:12:06 -060047void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) {
48 if (add_obj) {
49 instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type));
50 // Call base class
51 ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj);
52 }
53}
54
John Zulauf2bc1fde2020-04-24 15:09:51 -060055// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
56// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060057static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
58 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060059 const VkImageView *attachments = fb_state.createInfo.pAttachments;
60 uint32_t count = fb_state.createInfo.attachmentCount;
61 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070062 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060063 if (framebuffer_attachments) {
64 attachments = framebuffer_attachments->pAttachments;
65 count = framebuffer_attachments->attachmentCount;
66 }
67 }
68 return std::make_pair(count, attachments);
69}
70
John Zulauf64ffe552021-02-06 10:25:07 -070071template <typename ImageViewPointer, typename Get>
72std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
73 const Get &get_fn) {
74 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060075
76 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
77 const auto attachment_count = count_attachment.first;
78 const auto *attachments = count_attachment.second;
79 views.resize(attachment_count, nullptr);
80 for (uint32_t i = 0; i < attachment_count; i++) {
81 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070082 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060083 }
84 }
85 return views;
86}
87
John Zulauf64ffe552021-02-06 10:25:07 -070088std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetSharedAttachmentViews(
89 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
90 auto get_fn = [this](VkImageView handle) { return this->GetShared<IMAGE_VIEW_STATE>(handle); };
91 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
92}
93
locke-lunargd556cc32019-09-17 01:21:23 -060094#ifdef VK_USE_PLATFORM_ANDROID_KHR
95// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
96// This could also move into a seperate core_validation_android.cpp file... ?
97
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060098template <typename CreateInfo>
99VkFormatFeatureFlags ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
100 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700101 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600102 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700103 // VUID 01894 will catch if not found in map
104 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
105 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600106 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700107 }
locke-lunargd556cc32019-09-17 01:21:23 -0600108 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600109 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -0600110}
111
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700112void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
113 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
114 if (VK_SUCCESS != result) return;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700115 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700116 if (ahb_format_props) {
Jeremy Gebbenfc6f8152021-03-18 16:58:55 -0600117 ahb_ext_formats_map.emplace(ahb_format_props->externalFormat, ahb_format_props->formatFeatures);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700118 }
119}
120
locke-lunargd556cc32019-09-17 01:21:23 -0600121#else
122
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600123template <typename CreateInfo>
124VkFormatFeatureFlags ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
125 return 0;
126}
locke-lunargd556cc32019-09-17 01:21:23 -0600127
128#endif // VK_USE_PLATFORM_ANDROID_KHR
129
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600130VkFormatFeatureFlags GetImageFormatFeatures(VkPhysicalDevice physical_device, VkDevice device, VkImage image, VkFormat format,
131 VkImageTiling tiling) {
132 VkFormatFeatureFlags format_features = 0;
Petr Kraus44f1c482020-04-25 20:09:25 +0200133 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
134 // if format is AHB external format then the features are already set
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600135 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
136 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
137 nullptr};
138 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200139
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600140 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
141 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
142 nullptr};
143 format_properties_2.pNext = (void *)&drm_properties_list;
144 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
145 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
146 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
147 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
148 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200149
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600150 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
151 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
152 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
153 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200154 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200155 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600156 } else {
157 VkFormatProperties format_properties;
158 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
159 format_features =
160 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200161 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600162 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200163}
164
locke-lunargd556cc32019-09-17 01:21:23 -0600165void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
166 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
167 if (VK_SUCCESS != result) return;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 VkFormatFeatureFlags format_features = 0;
locke-lunargd556cc32019-09-17 01:21:23 -0600169 if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600170 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600171 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600172 if (format_features == 0) {
173 format_features = GetImageFormatFeatures(physical_device, device, *pImage, pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600174 }
175
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600176 auto is_node = std::make_shared<IMAGE_STATE>(device, *pImage, pCreateInfo, format_features);
locke-lunargd556cc32019-09-17 01:21:23 -0600177 // Record the memory requirements in case they won't be queried
sfricke-samsung013f1ef2020-05-14 22:56:20 -0700178 // External AHB memory can't be queried until after memory is bound
Jeremy Gebben6fbf8242021-06-21 09:14:46 -0600179 if (is_node->IsExternalAHB() == false) {
sfricke-samsung71bc6572020-04-29 15:49:43 -0700180 if (is_node->disjoint == false) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -0600181 DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements[0]);
sfricke-samsungd7ea5de2020-04-08 09:19:18 -0700182 } else {
183 uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
Jeremy Gebben0c09bc92021-08-11 13:58:16 -0600184 static const std::array<VkImageAspectFlagBits, 3> aspects{VK_IMAGE_ASPECT_PLANE_0_BIT, VK_IMAGE_ASPECT_PLANE_1_BIT,
185 VK_IMAGE_ASPECT_PLANE_2_BIT};
186 assert(plane_count <= aspects.size());
sfricke-samsungd7ea5de2020-04-08 09:19:18 -0700187 VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr};
Jeremy Gebben0c09bc92021-08-11 13:58:16 -0600188 VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, &image_plane_req,
189 *pImage};
sfricke-samsungd7ea5de2020-04-08 09:19:18 -0700190
Jeremy Gebben0c09bc92021-08-11 13:58:16 -0600191 for (uint32_t i = 0; i < plane_count; i++) {
192 VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr};
sfricke-samsungd7ea5de2020-04-08 09:19:18 -0700193
Jeremy Gebben0c09bc92021-08-11 13:58:16 -0600194 image_plane_req.planeAspect = aspects[i];
Jeremy Gebbenb9b07b62021-08-16 11:38:47 -0600195 switch (device_extensions.vk_khr_get_memory_requirements2) {
196 case kEnabledByApiLevel:
197 DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
198 break;
199 case kEnabledByCreateinfo:
200 DispatchGetImageMemoryRequirements2KHR(device, &mem_req_info2, &mem_reqs2);
201 break;
202 default:
203 // The VK_KHR_sampler_ycbcr_conversion extension requires VK_KHR_get_memory_requirements2,
204 // so validation of this vkCreateImage call should have already failed.
205 assert(false);
Jeremy Gebben0c09bc92021-08-11 13:58:16 -0600206 }
207 is_node->requirements[i] = mem_reqs2.memoryRequirements;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -0700208 }
209 }
locke-lunargd556cc32019-09-17 01:21:23 -0600210 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700211
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600212 imageMap[*pImage] = std::move(is_node);
locke-lunargd556cc32019-09-17 01:21:23 -0600213}
214
215void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
216 if (!image) return;
217 IMAGE_STATE *image_state = GetImageState(image);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600218 if (!image_state) return;
219
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600220 image_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -0600221 imageMap.erase(image);
222}
223
224void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
225 VkImageLayout imageLayout, const VkClearColorValue *pColor,
226 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600227
228 if (disabled[command_buffer_state]) return;
229
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600230 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600231 if (cb_node) {
232 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, GetImageState(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600233 }
234}
235
236void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
237 VkImageLayout imageLayout,
238 const VkClearDepthStencilValue *pDepthStencil,
239 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600240 if (disabled[command_buffer_state]) return;
241
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600242 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600243 if (cb_node) {
244 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, GetImageState(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600245 }
246}
247
248void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
249 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
250 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600251 if (disabled[command_buffer_state]) return;
252
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600253 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600254 cb_node->RecordTransferCmd(CMD_COPYIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600255}
256
Jeff Leger178b1e52020-10-05 12:22:23 -0400257void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
258 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600259 if (disabled[command_buffer_state]) return;
260
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600261 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600262 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, GetImageState(pCopyImageInfo->srcImage), GetImageState(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400263}
264
locke-lunargd556cc32019-09-17 01:21:23 -0600265void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
266 VkImageLayout srcImageLayout, VkImage dstImage,
267 VkImageLayout dstImageLayout, uint32_t regionCount,
268 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600269 if (disabled[command_buffer_state]) return;
270
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600271 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600272 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600273}
274
Jeff Leger178b1e52020-10-05 12:22:23 -0400275void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
276 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600277 if (disabled[command_buffer_state]) return;
278
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600279 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600280 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, GetImageState(pResolveImageInfo->srcImage),
281 GetImageState(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400282}
283
locke-lunargd556cc32019-09-17 01:21:23 -0600284void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
285 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
286 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600287 if (disabled[command_buffer_state]) return;
288
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600289 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600290 cb_node->RecordTransferCmd(CMD_BLITIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600291}
292
Jeff Leger178b1e52020-10-05 12:22:23 -0400293void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
294 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600295 if (disabled[command_buffer_state]) return;
296
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600297 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600298 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, GetImageState(pBlitImageInfo->srcImage), GetImageState(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400299}
300
locke-lunargd556cc32019-09-17 01:21:23 -0600301void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
302 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
303 VkResult result) {
304 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600305
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500306 auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600307
James Rumble2f6e7bb2021-07-13 15:21:20 +0100308 if (pCreateInfo) {
309 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
310 if (opaque_capture_address) {
311 // address is used for GPU-AV and ray tracing buffer validation
312 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
313 buffer_address_map_.emplace(opaque_capture_address->opaqueCaptureAddress, buffer_state.get());
314 }
315 }
316
locke-lunargd556cc32019-09-17 01:21:23 -0600317 // Get a set of requirements in the case the app does not
sfricke-samsungad90e722020-07-08 20:54:24 -0700318 DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements);
locke-lunargd556cc32019-09-17 01:21:23 -0600319
Jeremy Gebbencbf22862021-03-03 12:01:22 -0700320 bufferMap.emplace(*pBuffer, std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600321}
322
323void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
324 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
325 VkResult result) {
326 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600327
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500328 auto buffer_state = GetBufferShared(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600329
330 VkFormatProperties format_properties;
331 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
locke-lunarg25b6c352020-08-06 17:44:18 -0600332
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600333 bufferViewMap[*pView] =
334 std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, format_properties.bufferFeatures);
locke-lunargd556cc32019-09-17 01:21:23 -0600335}
336
337void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
338 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
339 VkResult result) {
340 if (result != VK_SUCCESS) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500341 auto image_state = GetImageShared(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700342
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600343 VkFormatFeatureFlags format_features = 0;
344 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700345 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600346 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700347 } else {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600348 format_features = GetImageFormatFeatures(physical_device, device, image_state->image(), pCreateInfo->format,
349 image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700350 }
351
locke-lunarg9939d4b2020-10-26 20:11:08 -0600352 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600353 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600354 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700355 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600356 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700357 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600358 image_format_info.type = image_state->createInfo.imageType;
359 image_format_info.format = image_state->createInfo.format;
360 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600361 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
362 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600363 image_format_info.flags = image_state->createInfo.flags;
364
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600365 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600366
367 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
368 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600369
370 imageViewMap[*pView] =
371 std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props);
locke-lunargd556cc32019-09-17 01:21:23 -0600372}
373
374void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
375 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600376 if (disabled[command_buffer_state]) return;
377
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600378 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600379 cb_node->RecordTransferCmd(CMD_COPYBUFFER, GetBufferState(srcBuffer), GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600380}
381
Jeff Leger178b1e52020-10-05 12:22:23 -0400382void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600383 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600384 if (disabled[command_buffer_state]) return;
385
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600386 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600387 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, GetBufferState(pCopyBufferInfo->srcBuffer),
388 GetBufferState(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400389}
390
locke-lunargd556cc32019-09-17 01:21:23 -0600391void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
392 const VkAllocationCallbacks *pAllocator) {
393 IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView);
394 if (!image_view_state) return;
locke-lunargd556cc32019-09-17 01:21:23 -0600395
396 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600397 image_view_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -0600398 imageViewMap.erase(imageView);
399}
400
401void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
402 if (!buffer) return;
403 auto buffer_state = GetBufferState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600404
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600405 buffer_state->Destroy();
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600406 bufferMap.erase(buffer_state->buffer());
locke-lunargd556cc32019-09-17 01:21:23 -0600407}
408
409void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
410 const VkAllocationCallbacks *pAllocator) {
411 if (!bufferView) return;
412 auto buffer_view_state = GetBufferViewState(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600413
414 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600415 buffer_view_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -0600416 bufferViewMap.erase(bufferView);
417}
418
419void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
420 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600421 if (disabled[command_buffer_state]) return;
422
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600423 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600424 cb_node->RecordTransferCmd(CMD_FILLBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600425}
426
427void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
428 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
429 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600430 if (disabled[command_buffer_state]) return;
431
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600432 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600433
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600434 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, GetImageState(srcImage), GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600435}
436
Jeff Leger178b1e52020-10-05 12:22:23 -0400437void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
438 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600439 if (disabled[command_buffer_state]) return;
440
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600441 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600442 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, GetImageState(pCopyImageToBufferInfo->srcImage),
443 GetBufferState(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400444}
445
locke-lunargd556cc32019-09-17 01:21:23 -0600446void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
447 VkImageLayout dstImageLayout, uint32_t regionCount,
448 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600449 if (disabled[command_buffer_state]) return;
450
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600451 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600452 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, GetBufferState(srcBuffer), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600453}
454
Jeff Leger178b1e52020-10-05 12:22:23 -0400455void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
456 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600457
458 if (disabled[command_buffer_state]) return;
459
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600460 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600461 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, GetBufferState(pCopyBufferToImageInfo->srcBuffer),
462 GetImageState(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400463}
464
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600465QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) {
466 auto it = queueMap.find(queue);
467 if (it == queueMap.end()) {
468 return nullptr;
469 }
470 return &it->second;
locke-lunargd556cc32019-09-17 01:21:23 -0600471}
472
Jeremy Gebben5570abe2021-05-16 18:35:13 -0600473const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const {
474 auto it = queueMap.find(queue);
475 if (it == queueMap.cend()) {
476 return nullptr;
477 }
478 return &it->second;
locke-lunargd556cc32019-09-17 01:21:23 -0600479}
480
locke-lunargd556cc32019-09-17 01:21:23 -0600481// Return ptr to memory binding for given handle of specified type
482template <typename State, typename Result>
483static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) {
484 switch (typed_handle.type) {
485 case kVulkanObjectTypeImage:
486 return state->GetImageState(typed_handle.Cast<VkImage>());
487 case kVulkanObjectTypeBuffer:
488 return state->GetBufferState(typed_handle.Cast<VkBuffer>());
489 case kVulkanObjectTypeAccelerationStructureNV:
sourav parmarcd5fb182020-07-17 12:58:44 -0700490 return state->GetAccelerationStructureStateNV(typed_handle.Cast<VkAccelerationStructureNV>());
locke-lunargd556cc32019-09-17 01:21:23 -0600491 default:
492 break;
493 }
494 return nullptr;
495}
496
497const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const {
498 return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle);
499}
500
501BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) {
502 return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle);
503}
504
locke-lunargd556cc32019-09-17 01:21:23 -0600505// Remove set from setMap and delete the set
506void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) {
Jeff Bolz41a1ced2019-10-11 11:40:49 -0500507 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600508 descriptor_set->Destroy();
Jeff Bolz41a1ced2019-10-11 11:40:49 -0500509
locke-lunargd556cc32019-09-17 01:21:23 -0600510 setMap.erase(descriptor_set->GetSet());
511}
512
513// Free all DS Pools including their Sets & related sub-structs
514// NOTE : Calls to this function should be wrapped in mutex
515void ValidationStateTracker::DeleteDescriptorSetPools() {
516 for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) {
517 // Remove this pools' sets from setMap and delete them
John Zulauf79f06582021-02-27 18:38:39 -0700518 for (auto *ds : ii->second->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -0600519 FreeDescriptorSet(ds);
520 }
521 ii->second->sets.clear();
522 ii = descriptorPoolMap.erase(ii);
523 }
524}
525
526// For given object struct return a ptr of BASE_NODE type for its wrapping struct
527BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) {
Jeff Bolzadbfa852019-10-04 13:53:30 -0500528 if (object_struct.node) {
529#ifdef _DEBUG
530 // assert that lookup would find the same object
531 VulkanTypedHandle other = object_struct;
532 other.node = nullptr;
533 assert(object_struct.node == GetStateStructPtrFromObject(other));
534#endif
535 return object_struct.node;
536 }
locke-lunargd556cc32019-09-17 01:21:23 -0600537 BASE_NODE *base_ptr = nullptr;
538 switch (object_struct.type) {
539 case kVulkanObjectTypeDescriptorSet: {
540 base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>());
541 break;
542 }
543 case kVulkanObjectTypeSampler: {
544 base_ptr = GetSamplerState(object_struct.Cast<VkSampler>());
545 break;
546 }
547 case kVulkanObjectTypeQueryPool: {
548 base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>());
549 break;
550 }
551 case kVulkanObjectTypePipeline: {
552 base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>());
553 break;
554 }
555 case kVulkanObjectTypeBuffer: {
556 base_ptr = GetBufferState(object_struct.Cast<VkBuffer>());
557 break;
558 }
559 case kVulkanObjectTypeBufferView: {
560 base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>());
561 break;
562 }
563 case kVulkanObjectTypeImage: {
564 base_ptr = GetImageState(object_struct.Cast<VkImage>());
565 break;
566 }
567 case kVulkanObjectTypeImageView: {
568 base_ptr = GetImageViewState(object_struct.Cast<VkImageView>());
569 break;
570 }
571 case kVulkanObjectTypeEvent: {
572 base_ptr = GetEventState(object_struct.Cast<VkEvent>());
573 break;
574 }
575 case kVulkanObjectTypeDescriptorPool: {
576 base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>());
577 break;
578 }
579 case kVulkanObjectTypeCommandPool: {
580 base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>());
581 break;
582 }
583 case kVulkanObjectTypeFramebuffer: {
584 base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>());
585 break;
586 }
587 case kVulkanObjectTypeRenderPass: {
588 base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>());
589 break;
590 }
591 case kVulkanObjectTypeDeviceMemory: {
592 base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>());
593 break;
594 }
595 case kVulkanObjectTypeAccelerationStructureNV: {
sourav parmarcd5fb182020-07-17 12:58:44 -0700596 base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>());
597 break;
598 }
599 case kVulkanObjectTypeAccelerationStructureKHR: {
600 base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>());
locke-lunargd556cc32019-09-17 01:21:23 -0600601 break;
602 }
Jeff Bolzadbfa852019-10-04 13:53:30 -0500603 case kVulkanObjectTypeUnknown:
604 // This can happen if an element of the object_bindings vector has been
605 // zeroed out, after an object is destroyed.
606 break;
locke-lunargd556cc32019-09-17 01:21:23 -0600607 default:
608 // TODO : Any other objects to be handled here?
609 assert(0);
610 break;
611 }
612 return base_ptr;
613}
614
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700615// Gets union of all features defined by Potential Format Features
616// except, does not handle the external format case for AHB as that only can be used for sampled images
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700617VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
618 VkFormatFeatureFlags format_features = 0;
619
620 if (format != VK_FORMAT_UNDEFINED) {
621 VkFormatProperties format_properties;
622 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
623 format_features |= format_properties.linearTilingFeatures;
624 format_features |= format_properties.optimalTilingFeatures;
625 if (device_extensions.vk_ext_image_drm_format_modifier) {
626 // VK_KHR_get_physical_device_properties2 is required in this case
627 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
628 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
629 nullptr};
630 format_properties_2.pNext = (void *)&drm_properties_list;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100631
632 // First call is to get the number of modifiers compatible with the queried format
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700633 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100634
635 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
636 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
637 drm_properties_list.pDrmFormatModifierProperties = drm_properties.data();
638
639 // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers
640 // compatible with the queried format
641 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
642
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700643 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
644 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
645 }
646 }
647 }
648
649 return format_features;
650}
651
locke-lunargd556cc32019-09-17 01:21:23 -0600652void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
653 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
654 VkResult result) {
655 if (VK_SUCCESS != result) return;
656
Locke Linf3873542021-04-26 11:25:10 -0600657 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
658 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
659 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
660
locke-lunargd556cc32019-09-17 01:21:23 -0600661 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
662 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700663 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600664 if (features2) {
665 enabled_features_found = &(features2->features);
Locke Linf3873542021-04-26 11:25:10 -0600666
667 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(features2->pNext);
668 if (provoking_vertex_features) {
669 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
670 }
locke-lunargd556cc32019-09-17 01:21:23 -0600671 }
672 }
673
locke-lunargd556cc32019-09-17 01:21:23 -0600674 if (nullptr == enabled_features_found) {
675 state_tracker->enabled_features.core = {};
676 } else {
677 state_tracker->enabled_features.core = *enabled_features_found;
678 }
679
locke-lunargd556cc32019-09-17 01:21:23 -0600680 // Save local link to this device's physical device state
Jeremy Gebben383b9a32021-09-08 16:31:33 -0600681 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu);
locke-lunargd556cc32019-09-17 01:21:23 -0600682
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700683 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700684 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700685 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700686 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700687 // Set Extension Feature Aliases to false as there is no struct to check
688 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
689 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
690 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
691 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
692 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
693 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800694 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700695
696 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700697
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700698 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700699 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700700 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
701 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
702 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
703 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700704 }
705
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700706 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700707 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700708 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
709 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700710 }
711
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700712 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700713 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700714 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
715 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
716 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
717 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
718 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
719 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
720 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
721 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
722 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
723 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
724 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
725 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
726 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
727 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
728 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
729 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
730 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
731 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
732 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
733 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
734 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
735 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
736 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
737 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
738 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
739 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
740 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
741 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
742 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
743 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
744 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
745 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
746 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
747 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
748 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
749 descriptor_indexing_features->descriptorBindingPartiallyBound;
750 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
751 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
752 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700753 }
754
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700755 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700756 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700757 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700758 }
759
760 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700761 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700762 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700763 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700764 }
765
766 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700767 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700768 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700769 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
770 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700771 }
772
773 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700774 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700775 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700776 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
777 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 }
779
780 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700781 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700782 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700783 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
784 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700785 }
786
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700787 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700788 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700789 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700790 }
791
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700792 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700793 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700794 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700795 }
796
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700797 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700798 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700799 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
800 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
801 buffer_device_address->bufferDeviceAddressCaptureReplay;
802 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
803 buffer_device_address->bufferDeviceAddressMultiDevice;
804 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800805
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700806 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800807 if (atomic_int64_features) {
808 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
809 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
810 }
811
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700812 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800813 if (memory_model_features) {
814 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
815 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
816 memory_model_features->vulkanMemoryModelDeviceScope;
817 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
818 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
819 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820 }
821
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700822 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700823 if (vulkan_11_features) {
824 state_tracker->enabled_features.core11 = *vulkan_11_features;
825 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700826 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700827
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700828 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700829 if (sixteen_bit_storage_features) {
830 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
831 sixteen_bit_storage_features->storageBuffer16BitAccess;
832 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
833 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
834 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
835 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
836 }
837
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700838 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700839 if (multiview_features) {
840 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
841 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
842 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
843 }
844
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700845 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700846 if (variable_pointers_features) {
847 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
848 variable_pointers_features->variablePointersStorageBuffer;
849 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
850 }
851
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700852 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700853 if (protected_memory_features) {
854 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
855 }
856
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700857 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700858 if (ycbcr_conversion_features) {
859 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
860 }
861
862 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700863 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700864 if (shader_draw_parameters_features) {
865 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700866 }
867 }
868
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700869 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600870 if (device_group_ci) {
871 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
872 state_tracker->device_group_create_info = *device_group_ci;
873 } else {
874 state_tracker->physical_device_count = 1;
875 }
locke-lunargd556cc32019-09-17 01:21:23 -0600876
sfricke-samsung828e59d2021-08-22 23:20:49 -0700877 // Features from other extensions passesd in create info
878 {
879 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
880 if (exclusive_scissor_features) {
881 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
882 }
locke-lunargd556cc32019-09-17 01:21:23 -0600883
sfricke-samsung828e59d2021-08-22 23:20:49 -0700884 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
885 if (shading_rate_image_features) {
886 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
887 }
locke-lunargd556cc32019-09-17 01:21:23 -0600888
sfricke-samsung828e59d2021-08-22 23:20:49 -0700889 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
890 if (mesh_shader_features) {
891 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
892 }
locke-lunargd556cc32019-09-17 01:21:23 -0600893
sfricke-samsung828e59d2021-08-22 23:20:49 -0700894 const auto *inline_uniform_block_features =
895 LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
896 if (inline_uniform_block_features) {
897 state_tracker->enabled_features.inline_uniform_block_features = *inline_uniform_block_features;
898 }
locke-lunargd556cc32019-09-17 01:21:23 -0600899
sfricke-samsung828e59d2021-08-22 23:20:49 -0700900 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
901 if (transform_feedback_features) {
902 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
903 }
locke-lunargd556cc32019-09-17 01:21:23 -0600904
sfricke-samsung828e59d2021-08-22 23:20:49 -0700905 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
906 if (vtx_attrib_div_features) {
907 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
908 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700909
sfricke-samsung828e59d2021-08-22 23:20:49 -0700910 const auto *buffer_device_address_ext_features =
911 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
912 if (buffer_device_address_ext_features) {
913 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
914 }
locke-lunargd556cc32019-09-17 01:21:23 -0600915
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
917 if (cooperative_matrix_features) {
918 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
919 }
locke-lunargd556cc32019-09-17 01:21:23 -0600920
sfricke-samsung828e59d2021-08-22 23:20:49 -0700921 const auto *compute_shader_derivatives_features =
922 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
923 if (compute_shader_derivatives_features) {
924 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
925 }
locke-lunargd556cc32019-09-17 01:21:23 -0600926
sfricke-samsung828e59d2021-08-22 23:20:49 -0700927 const auto *fragment_shader_barycentric_features =
928 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
929 if (fragment_shader_barycentric_features) {
930 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
931 }
locke-lunargd556cc32019-09-17 01:21:23 -0600932
sfricke-samsung828e59d2021-08-22 23:20:49 -0700933 const auto *shader_image_footprint_features =
934 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
935 if (shader_image_footprint_features) {
936 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
937 }
locke-lunargd556cc32019-09-17 01:21:23 -0600938
sfricke-samsung828e59d2021-08-22 23:20:49 -0700939 const auto *fragment_shader_interlock_features =
940 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
941 if (fragment_shader_interlock_features) {
942 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
943 }
locke-lunargd556cc32019-09-17 01:21:23 -0600944
sfricke-samsung828e59d2021-08-22 23:20:49 -0700945 const auto *demote_to_helper_invocation_features =
946 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
947 if (demote_to_helper_invocation_features) {
948 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
949 }
locke-lunargd556cc32019-09-17 01:21:23 -0600950
sfricke-samsung828e59d2021-08-22 23:20:49 -0700951 const auto *texel_buffer_alignment_features =
952 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
953 if (texel_buffer_alignment_features) {
954 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
955 }
locke-lunargd556cc32019-09-17 01:21:23 -0600956
sfricke-samsung828e59d2021-08-22 23:20:49 -0700957 const auto *pipeline_exe_props_features =
958 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
959 if (pipeline_exe_props_features) {
960 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
961 }
locke-lunargd556cc32019-09-17 01:21:23 -0600962
sfricke-samsung828e59d2021-08-22 23:20:49 -0700963 const auto *dedicated_allocation_image_aliasing_features =
964 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
965 if (dedicated_allocation_image_aliasing_features) {
966 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
967 *dedicated_allocation_image_aliasing_features;
968 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500969
sfricke-samsung828e59d2021-08-22 23:20:49 -0700970 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
971 if (performance_query_features) {
972 state_tracker->enabled_features.performance_query_features = *performance_query_features;
973 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100974
sfricke-samsung828e59d2021-08-22 23:20:49 -0700975 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
976 if (device_coherent_memory_features) {
977 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
978 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
981 if (ycbcr_image_array_features) {
982 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
983 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800984
sfricke-samsung828e59d2021-08-22 23:20:49 -0700985 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
986 if (ray_query_features) {
987 state_tracker->enabled_features.ray_query_features = *ray_query_features;
988 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700989
sfricke-samsung828e59d2021-08-22 23:20:49 -0700990 const auto *ray_tracing_pipeline_features =
991 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
992 if (ray_tracing_pipeline_features) {
993 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
994 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700995
sfricke-samsung828e59d2021-08-22 23:20:49 -0700996 const auto *ray_tracing_acceleration_structure_features =
997 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
998 if (ray_tracing_acceleration_structure_features) {
999 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
1000 *ray_tracing_acceleration_structure_features;
1001 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001002
sfricke-samsung828e59d2021-08-22 23:20:49 -07001003 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
1004 if (robustness2_features) {
1005 state_tracker->enabled_features.robustness2_features = *robustness2_features;
1006 }
Jeff Bolz165818a2020-05-08 11:19:03 -05001007
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 const auto *fragment_density_map_features =
1009 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1010 if (fragment_density_map_features) {
1011 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
1012 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001013
sfricke-samsung828e59d2021-08-22 23:20:49 -07001014 const auto *fragment_density_map_features2 =
1015 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1016 if (fragment_density_map_features2) {
1017 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
1018 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001019
sfricke-samsung828e59d2021-08-22 23:20:49 -07001020 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1021 if (astc_decode_features) {
1022 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
1023 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001024
sfricke-samsung828e59d2021-08-22 23:20:49 -07001025 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1026 if (custom_border_color_features) {
1027 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
1028 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001029
sfricke-samsung828e59d2021-08-22 23:20:49 -07001030 const auto *pipeline_creation_cache_control_features =
1031 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
1032 if (pipeline_creation_cache_control_features) {
1033 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
1034 }
sfricke-samsungfd661d62020-05-16 00:57:27 -07001035
sfricke-samsung828e59d2021-08-22 23:20:49 -07001036 const auto *fragment_shading_rate_features =
1037 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1038 if (fragment_shading_rate_features) {
1039 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
1040 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001041
sfricke-samsung828e59d2021-08-22 23:20:49 -07001042 const auto *extended_dynamic_state_features =
1043 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1044 if (extended_dynamic_state_features) {
1045 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
1046 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001047
sfricke-samsung828e59d2021-08-22 23:20:49 -07001048 const auto *extended_dynamic_state2_features =
1049 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1050 if (extended_dynamic_state2_features) {
1051 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
1052 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001053
sfricke-samsung828e59d2021-08-22 23:20:49 -07001054 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1055 if (multiview_features) {
1056 state_tracker->enabled_features.multiview_features = *multiview_features;
1057 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001058
sfricke-samsung828e59d2021-08-22 23:20:49 -07001059 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1060 if (portability_features) {
1061 state_tracker->enabled_features.portability_subset_features = *portability_features;
1062 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001063
sfricke-samsung828e59d2021-08-22 23:20:49 -07001064 const auto *shader_integer_functions2_features =
1065 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1066 if (shader_integer_functions2_features) {
1067 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1068 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001069
sfricke-samsung828e59d2021-08-22 23:20:49 -07001070 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1071 if (shader_sm_builtins_features) {
1072 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
1073 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001074
sfricke-samsung828e59d2021-08-22 23:20:49 -07001075 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1076 if (shader_atomic_float_features) {
1077 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
1078 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *shader_image_atomic_int64_features =
1081 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1082 if (shader_image_atomic_int64_features) {
1083 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1084 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001085
sfricke-samsung828e59d2021-08-22 23:20:49 -07001086 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1087 if (shader_clock_features) {
1088 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1089 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001090
sfricke-samsung828e59d2021-08-22 23:20:49 -07001091 const auto *conditional_rendering_features =
1092 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1093 if (conditional_rendering_features) {
1094 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1095 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001096
sfricke-samsung828e59d2021-08-22 23:20:49 -07001097 const auto *workgroup_memory_explicit_layout_features =
1098 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1099 if (workgroup_memory_explicit_layout_features) {
1100 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1101 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001102
sfricke-samsung828e59d2021-08-22 23:20:49 -07001103 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext);
1104 if (synchronization2_features) {
1105 state_tracker->enabled_features.synchronization2_features = *synchronization2_features;
1106 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001107
sfricke-samsung828e59d2021-08-22 23:20:49 -07001108 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1109 if (provoking_vertex_features) {
1110 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1111 }
Locke Linf3873542021-04-26 11:25:10 -06001112
sfricke-samsung828e59d2021-08-22 23:20:49 -07001113 const auto *vertex_input_dynamic_state_features =
1114 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1115 if (vertex_input_dynamic_state_features) {
1116 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1117 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001118
sfricke-samsung828e59d2021-08-22 23:20:49 -07001119 const auto *inherited_viewport_scissor_features =
1120 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1121 if (inherited_viewport_scissor_features) {
1122 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1123 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001124
sfricke-samsung828e59d2021-08-22 23:20:49 -07001125 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1126 if (multi_draw_features) {
1127 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1128 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001129
sfricke-samsung828e59d2021-08-22 23:20:49 -07001130 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1131 if (color_write_features) {
1132 state_tracker->enabled_features.color_write_features = *color_write_features;
1133 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001134
sfricke-samsung828e59d2021-08-22 23:20:49 -07001135 const auto *shader_atomic_float2_features =
1136 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1137 if (shader_atomic_float2_features) {
1138 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1139 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001140
sfricke-samsung828e59d2021-08-22 23:20:49 -07001141 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1142 if (present_id_features) {
1143 state_tracker->enabled_features.present_id_features = *present_id_features;
1144 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001145
sfricke-samsung828e59d2021-08-22 23:20:49 -07001146 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1147 if (present_wait_features) {
1148 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1149 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001150
1151 const auto *ray_tracing_motion_blur_features =
1152 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1153 if (ray_tracing_motion_blur_features) {
1154 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1155 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001156
1157 const auto *shader_integer_dot_product_features =
1158 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
1159 if (shader_integer_dot_product_features) {
1160 state_tracker->enabled_features.shader_integer_dot_product_features = *shader_integer_dot_product_features;
1161 }
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001162
1163 const auto *primitive_topology_list_restart_features =
1164 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1165 if (primitive_topology_list_restart_features) {
1166 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1167 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001168 }
1169
locke-lunargd556cc32019-09-17 01:21:23 -06001170 // Store physical device properties and physical device mem limits into CoreChecks structs
1171 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1172 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1173
1174 const auto &dev_ext = state_tracker->device_extensions;
1175 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1176
sfricke-samsung828e59d2021-08-22 23:20:49 -07001177 // Vulkan 1.2 can get properties from single struct, otherwise need to add to it per extension
1178 if (state_tracker->device_extensions.vk_feature_version_1_2) {
1179 GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2,
1180 &state_tracker->phys_dev_props_core11);
1181 GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2,
1182 &state_tracker->phys_dev_props_core12);
1183 } else {
1184 // VkPhysicalDeviceVulkan11Properties
1185 //
1186 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1187
1188 if (dev_ext.vk_khr_multiview) {
1189 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1190 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1191 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1192 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1193 }
1194
1195 if (dev_ext.vk_khr_maintenance3) {
1196 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1197 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1198 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1199 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1200 }
1201
1202 // Some 1.1 properties were added to core without previous extensions
1203 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1204 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1205 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1206 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1207 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1208
1209 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1210 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1211 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1212 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1213
1214 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1215 }
1216
1217 // VkPhysicalDeviceVulkan12Properties
1218 //
1219 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1220
1221 if (dev_ext.vk_ext_descriptor_indexing) {
1222 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1223 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1224 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1225 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1226 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1227 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1228 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1229 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1230 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1231 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1232 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1233 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1234 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1235 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1236 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1237 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1238 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1239 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1240 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1241 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1242 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1243 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1244 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1245 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1246 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1247 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1248 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1249 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1250 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1251 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1252 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1253 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1254 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1255 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1256 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1257 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1258 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1259 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1260 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1261 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1262 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1263 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1264 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1265 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1266 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1267 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1268 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1269 }
1270
1271 if (dev_ext.vk_khr_depth_stencil_resolve) {
1272 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1273 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1274 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1275 depth_stencil_resolve_props.supportedDepthResolveModes;
1276 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1277 depth_stencil_resolve_props.supportedStencilResolveModes;
1278 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1279 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1280 }
1281
1282 if (dev_ext.vk_khr_timeline_semaphore) {
1283 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1284 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1285 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1286 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1287 }
1288
1289 if (dev_ext.vk_ext_sampler_filter_minmax) {
1290 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1291 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1292 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1293 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1294 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1295 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1296 }
1297
1298 if (dev_ext.vk_khr_shader_float_controls) {
1299 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1300 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1301 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1302 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1303 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1304 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1305 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1306 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1307 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1308 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1309 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1310 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1311 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1312 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1313 float_controls_props.shaderDenormFlushToZeroFloat16;
1314 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1315 float_controls_props.shaderDenormFlushToZeroFloat32;
1316 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1317 float_controls_props.shaderDenormFlushToZeroFloat64;
1318 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1319 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1320 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1321 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1322 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1323 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1324 }
locke-lunargd556cc32019-09-17 01:21:23 -06001325 }
1326
sfricke-samsung828e59d2021-08-22 23:20:49 -07001327 // Extensions with properties to extract to DeviceExtensionProperties
1328 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001329 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1330 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1331 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1332 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001333 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001334 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001335 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1336 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001337 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1338 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001339 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001340 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001341 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001342 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001343 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001344 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001345 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001346 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001347 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001348 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001349 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001350
locke-lunargd556cc32019-09-17 01:21:23 -06001351 if (state_tracker->device_extensions.vk_nv_cooperative_matrix) {
1352 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001353 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1354 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001355 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1356 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1357
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001358 uint32_t num_cooperative_matrix_properties = 0;
1359 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1360 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001361 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001362
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001363 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001364 state_tracker->cooperative_matrix_properties.data());
1365 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001366
locke-lunargd556cc32019-09-17 01:21:23 -06001367 // Store queue family data
1368 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1369 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001370 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001371 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1372 state_tracker->device_queue_info_list.push_back(
1373 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
locke-lunargd556cc32019-09-17 01:21:23 -06001374 }
1375 }
1376}
1377
1378void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1379 if (!device) return;
1380
locke-lunargd556cc32019-09-17 01:21:23 -06001381 // Reset all command buffers before destroying them, to unlink object_bindings.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001382 for (auto &command_buffer : commandBufferMap) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001383 command_buffer.second->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001384 }
Jeff Bolzadbfa852019-10-04 13:53:30 -05001385 pipelineMap.clear();
1386 renderPassMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001387 commandBufferMap.clear();
1388
1389 // This will also delete all sets in the pool & remove them from setMap
1390 DeleteDescriptorSetPools();
1391 // All sets should be removed
1392 assert(setMap.empty());
1393 descriptorSetLayoutMap.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001394 // Because swapchains are associated with Surfaces, which are at instance level,
1395 // they need to be explicitly destroyed here to avoid continued references to
1396 // the device we're destroying.
1397 for (auto &entry : swapchainMap) {
1398 entry.second->Destroy();
1399 }
1400 swapchainMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001401 imageViewMap.clear();
1402 imageMap.clear();
1403 bufferViewMap.clear();
1404 bufferMap.clear();
1405 // Queues persist until device is destroyed
1406 queueMap.clear();
1407}
1408
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001409void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) {
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001410 layer_data::unordered_map<VkQueue, uint64_t> other_queue_seqs;
1411 layer_data::unordered_map<VkSemaphore, uint64_t> timeline_semaphore_counters;
locke-lunargd556cc32019-09-17 01:21:23 -06001412
1413 // Roll this queue forward, one submission at a time.
1414 while (pQueue->seq < seq) {
1415 auto &submission = pQueue->submissions.front();
1416
1417 for (auto &wait : submission.waitSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001418 auto semaphore_state = GetSemaphoreState(wait.semaphore);
1419 if (semaphore_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001420 semaphore_state->EndUse();
locke-lunargd556cc32019-09-17 01:21:23 -06001421 }
Mike Schuchardt2df08912020-12-15 16:28:09 -08001422 if (wait.type == VK_SEMAPHORE_TYPE_TIMELINE) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001423 auto &last_counter = timeline_semaphore_counters[wait.semaphore];
1424 last_counter = std::max(last_counter, wait.payload);
Marshall Drew-Brook03847582020-11-06 15:10:45 -08001425 } else {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001426 auto &last_seq = other_queue_seqs[wait.queue];
1427 last_seq = std::max(last_seq, wait.seq);
Marshall Drew-Brook03847582020-11-06 15:10:45 -08001428 }
locke-lunargd556cc32019-09-17 01:21:23 -06001429 }
1430
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01001431 for (auto &signal : submission.signalSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001432 auto semaphore_state = GetSemaphoreState(signal.semaphore);
1433 if (semaphore_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001434 semaphore_state->EndUse();
Mike Schuchardt2df08912020-12-15 16:28:09 -08001435 if (semaphore_state->type == VK_SEMAPHORE_TYPE_TIMELINE && semaphore_state->payload < signal.payload) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001436 semaphore_state->payload = signal.payload;
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01001437 }
locke-lunargd556cc32019-09-17 01:21:23 -06001438 }
1439 }
1440
1441 for (auto &semaphore : submission.externalSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001442 auto semaphore_state = GetSemaphoreState(semaphore);
1443 if (semaphore_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001444 semaphore_state->EndUse();
locke-lunargd556cc32019-09-17 01:21:23 -06001445 }
1446 }
1447
1448 for (auto cb : submission.cbs) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06001449 auto cb_node = Get<CMD_BUFFER_STATE>(cb);
locke-lunargd556cc32019-09-17 01:21:23 -06001450 if (!cb_node) {
1451 continue;
1452 }
1453 // First perform decrement on general case bound objects
locke-lunargd556cc32019-09-17 01:21:23 -06001454 for (auto event : cb_node->writeEventsBeforeWait) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001455 auto event_node = eventMap.find(event);
1456 if (event_node != eventMap.end()) {
John Zulauf48057322020-12-02 11:59:31 -07001457 event_node->second->write_in_use--;
locke-lunargd556cc32019-09-17 01:21:23 -06001458 }
1459 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001460 QueryMap local_query_to_state_map;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001461 VkQueryPool first_pool = VK_NULL_HANDLE;
Jeff Bolz310775c2019-10-09 00:46:33 -05001462 for (auto &function : cb_node->queryUpdates) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001463 function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map);
Jeff Bolz310775c2019-10-09 00:46:33 -05001464 }
1465
John Zulauf79f06582021-02-27 18:38:39 -07001466 for (const auto &query_state_pair : local_query_to_state_map) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001467 if (query_state_pair.second == QUERYSTATE_ENDED) {
1468 queryToStateMap[query_state_pair.first] = QUERYSTATE_AVAILABLE;
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001469 }
locke-lunargd556cc32019-09-17 01:21:23 -06001470 }
Jeremy Gebben5570abe2021-05-16 18:35:13 -06001471 if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
1472 cb_node->EndUse();
1473 }
locke-lunargd556cc32019-09-17 01:21:23 -06001474 }
1475
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001476 auto fence_state = GetFenceState(submission.fence);
1477 if (fence_state && fence_state->scope == kSyncScopeInternal) {
1478 fence_state->state = FENCE_RETIRED;
locke-lunargd556cc32019-09-17 01:21:23 -06001479 }
1480
1481 pQueue->submissions.pop_front();
1482 pQueue->seq++;
1483 }
1484
1485 // Roll other queues forward to the highest seq we saw a wait for
John Zulauf79f06582021-02-27 18:38:39 -07001486 for (const auto &qs : other_queue_seqs) {
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001487 RetireWorkOnQueue(GetQueueState(qs.first), qs.second);
locke-lunargd556cc32019-09-17 01:21:23 -06001488 }
John Zulauf79f06582021-02-27 18:38:39 -07001489 for (const auto &sc : timeline_semaphore_counters) {
Marshall Drew-Brook03847582020-11-06 15:10:45 -08001490 RetireTimelineSemaphore(sc.first, sc.second);
1491 }
locke-lunargd556cc32019-09-17 01:21:23 -06001492}
1493
1494// Submit a fence to a queue, delimiting previous fences and previous untracked
1495// work by it.
1496static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) {
1497 pFence->state = FENCE_INFLIGHT;
1498 pFence->signaler.first = pQueue->queue;
1499 pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount;
1500}
1501
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001502uint64_t ValidationStateTracker::RecordSubmitFence(QUEUE_STATE *queue_state, VkFence fence, uint32_t submit_count) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001503 auto fence_state = GetFenceState(fence);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001504 uint64_t early_retire_seq = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001505 if (fence_state) {
1506 if (fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06001507 // Mark fence in use
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001508 SubmitFence(queue_state, fence_state, std::max(1u, submit_count));
1509 if (!submit_count) {
locke-lunargd556cc32019-09-17 01:21:23 -06001510 // If no submissions, but just dropping a fence on the end of the queue,
1511 // record an empty submission with just the fence, so we can determine
1512 // its completion.
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001513 CB_SUBMISSION submission;
1514 submission.fence = fence;
1515 queue_state->submissions.emplace_back(std::move(submission));
locke-lunargd556cc32019-09-17 01:21:23 -06001516 }
1517 } else {
1518 // Retire work up until this fence early, we will not see the wait that corresponds to this signal
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001519 early_retire_seq = queue_state->seq + queue_state->submissions.size();
locke-lunargd556cc32019-09-17 01:21:23 -06001520 }
1521 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001522 return early_retire_seq;
1523}
1524
1525void ValidationStateTracker::RecordSubmitCommandBuffer(CB_SUBMISSION &submission, VkCommandBuffer command_buffer) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06001526 auto cb_node = Get<CMD_BUFFER_STATE>(command_buffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001527 if (cb_node) {
1528 submission.cbs.push_back(command_buffer);
John Zulauf79f06582021-02-27 18:38:39 -07001529 for (auto *secondary_cmd_buffer : cb_node->linkedCommandBuffers) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001530 submission.cbs.push_back(secondary_cmd_buffer->commandBuffer());
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001531 secondary_cmd_buffer->IncrementResources();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001532 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001533 cb_node->IncrementResources();
Jeremy Gebben5570abe2021-05-16 18:35:13 -06001534 // increment use count for all bound objects including secondary cbs
1535 cb_node->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001536
1537 VkQueryPool first_pool = VK_NULL_HANDLE;
1538 EventToStageMap local_event_to_stage_map;
1539 QueryMap local_query_to_state_map;
1540 for (auto &function : cb_node->queryUpdates) {
1541 function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map);
1542 }
1543
John Zulauf79f06582021-02-27 18:38:39 -07001544 for (const auto &query_state_pair : local_query_to_state_map) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001545 queryToStateMap[query_state_pair.first] = query_state_pair.second;
1546 }
1547
John Zulauf79f06582021-02-27 18:38:39 -07001548 for (const auto &function : cb_node->eventUpdates) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001549 function(nullptr, /*do_validate*/ false, &local_event_to_stage_map);
1550 }
1551
John Zulauf79f06582021-02-27 18:38:39 -07001552 for (const auto &eventStagePair : local_event_to_stage_map) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001553 eventMap[eventStagePair.first]->stageMask = eventStagePair.second;
1554 }
1555 }
1556}
1557
1558void ValidationStateTracker::RecordSubmitWaitSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore,
1559 uint64_t value, uint64_t next_seq) {
1560 auto semaphore_state = GetSemaphoreState(semaphore);
1561 if (semaphore_state) {
1562 if (semaphore_state->scope == kSyncScopeInternal) {
1563 SEMAPHORE_WAIT wait;
1564 wait.semaphore = semaphore;
1565 wait.type = semaphore_state->type;
1566 if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) {
1567 if (semaphore_state->signaler.first != VK_NULL_HANDLE) {
1568 wait.queue = semaphore_state->signaler.first;
1569 wait.seq = semaphore_state->signaler.second;
1570 submission.waitSemaphores.emplace_back(std::move(wait));
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001571 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001572 }
1573 semaphore_state->signaler.first = VK_NULL_HANDLE;
1574 semaphore_state->signaled = false;
1575 } else if (semaphore_state->payload < value) {
1576 wait.queue = queue;
1577 wait.seq = next_seq;
1578 wait.payload = value;
1579 submission.waitSemaphores.emplace_back(std::move(wait));
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001580 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001581 }
1582 } else {
1583 submission.externalSemaphores.push_back(semaphore);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001584 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001585 if (semaphore_state->scope == kSyncScopeExternalTemporary) {
1586 semaphore_state->scope = kSyncScopeInternal;
1587 }
1588 }
1589 }
1590}
1591
1592bool ValidationStateTracker::RecordSubmitSignalSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore,
1593 uint64_t value, uint64_t next_seq) {
1594 bool retire_early = false;
1595 auto semaphore_state = GetSemaphoreState(semaphore);
1596 if (semaphore_state) {
1597 if (semaphore_state->scope == kSyncScopeInternal) {
1598 SEMAPHORE_SIGNAL signal;
1599 signal.semaphore = semaphore;
1600 signal.seq = next_seq;
1601 if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) {
1602 semaphore_state->signaler.first = queue;
1603 semaphore_state->signaler.second = next_seq;
1604 semaphore_state->signaled = true;
1605 } else {
1606 signal.payload = value;
1607 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001608 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001609 submission.signalSemaphores.emplace_back(std::move(signal));
1610 } else {
1611 // Retire work up until this submit early, we will not see the wait that corresponds to this signal
1612 retire_early = true;
1613 }
1614 }
1615 return retire_early;
1616}
1617
1618void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1619 VkFence fence, VkResult result) {
1620 if (result != VK_SUCCESS) return;
1621 auto queue_state = GetQueueState(queue);
1622
1623 uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount);
locke-lunargd556cc32019-09-17 01:21:23 -06001624
1625 // Now process each individual submit
1626 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001627 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001628 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001629 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001630 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001631 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001632 uint64_t value = 0;
1633 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1634 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1635 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1636 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001637 RecordSubmitWaitSemaphore(submission, queue, submit->pWaitSemaphores[i], value, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001639
1640 bool retire_early = false;
locke-lunargd556cc32019-09-17 01:21:23 -06001641 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001642 uint64_t value = 0;
1643 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1644 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1645 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1646 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001647 retire_early |= RecordSubmitSignalSemaphore(submission, queue, submit->pSignalSemaphores[i], value, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001648 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001649 if (retire_early) {
1650 early_retire_seq = std::max(early_retire_seq, next_seq);
1651 }
1652
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001653 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001654 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001655
locke-lunargd556cc32019-09-17 01:21:23 -06001656 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001657 RecordSubmitCommandBuffer(submission, submit->pCommandBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06001658 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001659 submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE;
1660 queue_state->submissions.emplace_back(std::move(submission));
1661 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001662
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001663 if (early_retire_seq) {
1664 RetireWorkOnQueue(queue_state, early_retire_seq);
1665 }
1666}
1667
1668void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1669 VkFence fence, VkResult result) {
1670 if (result != VK_SUCCESS) return;
1671 auto queue_state = GetQueueState(queue);
1672
1673 uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount);
1674
1675 // Now process each individual submit
1676 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1677 CB_SUBMISSION submission;
1678 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
1679 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
1680 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1681 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
1682 RecordSubmitWaitSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq);
1683 }
1684 bool retire_early = false;
1685 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1686 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
1687 retire_early |= RecordSubmitSignalSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq);
1688 }
1689 if (retire_early) {
1690 early_retire_seq = std::max(early_retire_seq, next_seq);
1691 }
1692 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1693 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1694
1695 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
1696 RecordSubmitCommandBuffer(submission, submit->pCommandBufferInfos[i].commandBuffer);
1697 }
1698 submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE;
1699 queue_state->submissions.emplace_back(std::move(submission));
locke-lunargd556cc32019-09-17 01:21:23 -06001700 }
1701
1702 if (early_retire_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001703 RetireWorkOnQueue(queue_state, early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001704 }
1705}
1706
1707void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1708 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1709 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001710 if (VK_SUCCESS != result) {
1711 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001712 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001713 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1714 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1715 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1716
1717 layer_data::optional<DedicatedBinding> dedicated_binding;
1718
1719 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1720 if (dedicated) {
1721 if (dedicated->buffer) {
1722 const auto *buffer_state = GetBufferState(dedicated->buffer);
1723 assert(buffer_state);
1724 if (!buffer_state) {
1725 return;
1726 }
1727 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1728 } else if (dedicated->image) {
1729 const auto *image_state = GetImageState(dedicated->image);
1730 assert(image_state);
1731 if (!image_state) {
1732 return;
1733 }
1734 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1735 }
1736 }
1737 memObjMap[*pMemory] = std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1738 std::move(dedicated_binding));
locke-lunargd556cc32019-09-17 01:21:23 -06001739 return;
1740}
1741
1742void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
1743 if (!mem) return;
1744 DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001745 if (!mem_info) return;
locke-lunargd556cc32019-09-17 01:21:23 -06001746 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001747 mem_info->Destroy();
John Zulauf79952712020-04-07 11:25:54 -06001748 fake_memory.Free(mem_info->fake_base_address);
locke-lunargd556cc32019-09-17 01:21:23 -06001749 memObjMap.erase(mem);
1750}
1751
1752void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1753 VkFence fence, VkResult result) {
1754 if (result != VK_SUCCESS) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001755 auto queue_state = GetQueueState(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001756
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001757 uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, bindInfoCount);
locke-lunargd556cc32019-09-17 01:21:23 -06001758
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001759 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1760 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001761 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001762 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1763 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1764 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001765 auto buffer_state = GetBufferState(bind_info.pBufferBinds[j].buffer);
1766 auto mem_state = GetDevMemShared(sparse_binding.memory);
1767 if (buffer_state && mem_state) {
1768 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1769 }
locke-lunargd556cc32019-09-17 01:21:23 -06001770 }
1771 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001772 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1773 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1774 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001775 auto image_state = GetImageState(bind_info.pImageOpaqueBinds[j].image);
1776 auto mem_state = GetDevMemShared(sparse_binding.memory);
1777 if (image_state && mem_state) {
1778 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1779 }
locke-lunargd556cc32019-09-17 01:21:23 -06001780 }
1781 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001782 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1783 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1784 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001785 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1786 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001787 auto image_state = GetImageState(bind_info.pImageBinds[j].image);
1788 auto mem_state = GetDevMemShared(sparse_binding.memory);
1789 if (image_state && mem_state) {
1790 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1791 }
locke-lunargd556cc32019-09-17 01:21:23 -06001792 }
1793 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001794 CB_SUBMISSION submission;
1795 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001796 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001797 RecordSubmitWaitSemaphore(submission, queue, bind_info.pWaitSemaphores[i], 0, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001798 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001799 bool retire_early = false;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001800 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001801 retire_early |= RecordSubmitSignalSemaphore(submission, queue, bind_info.pSignalSemaphores[i], 0, next_seq);
1802 }
1803 // Retire work up until this submit early, we will not see the wait that corresponds to this signal
1804 if (retire_early) {
1805 early_retire_seq = std::max(early_retire_seq, queue_state->seq + queue_state->submissions.size() + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06001806 }
1807
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001808 submission.fence = bind_idx == (bindInfoCount - 1) ? fence : VK_NULL_HANDLE;
1809 queue_state->submissions.emplace_back(std::move(submission));
locke-lunargd556cc32019-09-17 01:21:23 -06001810 }
1811
1812 if (early_retire_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001813 RetireWorkOnQueue(queue_state, early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001814 }
1815}
1816
1817void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1818 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1819 VkResult result) {
1820 if (VK_SUCCESS != result) return;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001821 semaphoreMap[*pSemaphore] = std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext));
locke-lunargd556cc32019-09-17 01:21:23 -06001822}
1823
Mike Schuchardt2df08912020-12-15 16:28:09 -08001824void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1825 VkSemaphoreImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06001826 SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore);
1827 if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001828 if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06001829 sema_node->scope == kSyncScopeInternal) {
1830 sema_node->scope = kSyncScopeExternalTemporary;
1831 } else {
1832 sema_node->scope = kSyncScopeExternalPermanent;
1833 }
1834 }
1835}
1836
Mike Schuchardt2df08912020-12-15 16:28:09 -08001837void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001838 VkResult result) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001839 auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore);
1840 semaphore_state->payload = pSignalInfo->value;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001841}
1842
locke-lunargd556cc32019-09-17 01:21:23 -06001843void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
1844 auto mem_info = GetDevMemState(mem);
1845 if (mem_info) {
1846 mem_info->mapped_range.offset = offset;
1847 mem_info->mapped_range.size = size;
1848 mem_info->p_driver_data = *ppData;
1849 }
1850}
1851
1852void ValidationStateTracker::RetireFence(VkFence fence) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001853 auto fence_state = GetFenceState(fence);
1854 if (fence_state && fence_state->scope == kSyncScopeInternal) {
1855 if (fence_state->signaler.first != VK_NULL_HANDLE) {
locke-lunargd556cc32019-09-17 01:21:23 -06001856 // Fence signaller is a queue -- use this as proof that prior operations on that queue have completed.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001857 RetireWorkOnQueue(GetQueueState(fence_state->signaler.first), fence_state->signaler.second);
locke-lunargd556cc32019-09-17 01:21:23 -06001858 } else {
1859 // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark
1860 // the fence as retired.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001861 fence_state->state = FENCE_RETIRED;
locke-lunargd556cc32019-09-17 01:21:23 -06001862 }
1863 }
1864}
1865
1866void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1867 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1868 if (VK_SUCCESS != result) return;
1869
1870 // When we know that all fences are complete we can clean/remove their CBs
1871 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1872 for (uint32_t i = 0; i < fenceCount; i++) {
1873 RetireFence(pFences[i]);
1874 }
1875 }
1876 // NOTE : Alternate case not handled here is when some fences have completed. In
1877 // this case for app to guarantee which fences completed it will have to call
1878 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1879}
1880
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001881void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001882 auto semaphore_state = GetSemaphoreState(semaphore);
1883 if (semaphore_state) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001884 for (auto &pair : queueMap) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001885 QUEUE_STATE &queue_state = pair.second;
Tony-LunarG47d5e272020-04-07 15:35:55 -06001886 uint64_t max_seq = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001887 for (const auto &submission : queue_state.submissions) {
1888 for (const auto &signal_semaphore : submission.signalSemaphores) {
1889 if (signal_semaphore.semaphore == semaphore && signal_semaphore.payload <= until_payload) {
1890 if (signal_semaphore.seq > max_seq) {
1891 max_seq = signal_semaphore.seq;
Tony-LunarG47d5e272020-04-07 15:35:55 -06001892 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001893 }
1894 }
1895 }
Tony-LunarG47d5e272020-04-07 15:35:55 -06001896 if (max_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001897 RetireWorkOnQueue(&queue_state, max_seq);
Tony-LunarG47d5e272020-04-07 15:35:55 -06001898 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001899 }
1900 }
1901}
1902
John Zulauff89de662020-04-13 18:57:34 -06001903void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1904 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001905 if (VK_SUCCESS != result) return;
1906
1907 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1908 RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]);
1909 }
1910}
1911
John Zulauff89de662020-04-13 18:57:34 -06001912void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1913 VkResult result) {
1914 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1915}
1916
1917void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1918 uint64_t timeout, VkResult result) {
1919 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1920}
1921
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001922void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1923 VkResult result) {
1924 if (VK_SUCCESS != result) return;
1925
1926 RetireTimelineSemaphore(semaphore, *pValue);
1927}
1928
1929void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1930 VkResult result) {
1931 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1932}
1933void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1934 VkResult result) {
1935 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1936}
1937
locke-lunargd556cc32019-09-17 01:21:23 -06001938void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1939 if (VK_SUCCESS != result) return;
1940 RetireFence(fence);
1941}
1942
1943void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) {
Jeremy Gebben5573a8c2021-06-04 08:55:10 -06001944 queueMap.emplace(queue, QUEUE_STATE(queue, queue_family_index));
locke-lunargd556cc32019-09-17 01:21:23 -06001945}
1946
1947void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1948 VkQueue *pQueue) {
1949 RecordGetDeviceQueueState(queueFamilyIndex, *pQueue);
1950}
1951
1952void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1953 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue);
1954}
1955
1956void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1957 if (VK_SUCCESS != result) return;
1958 QUEUE_STATE *queue_state = GetQueueState(queue);
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001959 RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size());
locke-lunargd556cc32019-09-17 01:21:23 -06001960}
1961
1962void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1963 if (VK_SUCCESS != result) return;
1964 for (auto &queue : queueMap) {
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001965 RetireWorkOnQueue(&queue.second, queue.second.seq + queue.second.submissions.size());
locke-lunargd556cc32019-09-17 01:21:23 -06001966 }
1967}
1968
1969void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
1970 if (!fence) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001971 auto fence_state = GetFenceState(fence);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001972 fence_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001973 fenceMap.erase(fence);
1974}
1975
1976void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1977 const VkAllocationCallbacks *pAllocator) {
1978 if (!semaphore) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001979 auto semaphore_state = GetSemaphoreState(semaphore);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001980 semaphore_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001981 semaphoreMap.erase(semaphore);
1982}
1983
1984void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
1985 if (!event) return;
John Zulauf48057322020-12-02 11:59:31 -07001986 EVENT_STATE *event_state = Get<EVENT_STATE>(event);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001987 event_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001988 eventMap.erase(event);
1989}
1990
1991void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1992 const VkAllocationCallbacks *pAllocator) {
1993 if (!queryPool) return;
1994 QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001995 qp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001996 queryPoolMap.erase(queryPool);
1997}
1998
locke-lunargd556cc32019-09-17 01:21:23 -06001999void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
2000 BUFFER_STATE *buffer_state = GetBufferState(buffer);
2001 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002002 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002003 auto mem_state = GetDevMemShared(mem);
2004 if (mem_state) {
2005 buffer_state->SetMemBinding(mem_state, memoryOffset);
2006 }
locke-lunargd556cc32019-09-17 01:21:23 -06002007 }
2008}
2009
2010void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
2011 VkDeviceSize memoryOffset, VkResult result) {
2012 if (VK_SUCCESS != result) return;
2013 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
2014}
2015
2016void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002017 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002018 for (uint32_t i = 0; i < bindInfoCount; i++) {
2019 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
2020 }
2021}
2022
2023void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002024 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002025 for (uint32_t i = 0; i < bindInfoCount; i++) {
2026 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
2027 }
2028}
2029
Spencer Fricke6c127102020-04-16 06:25:20 -07002030void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
locke-lunargd556cc32019-09-17 01:21:23 -06002031 BUFFER_STATE *buffer_state = GetBufferState(buffer);
2032 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002033 buffer_state->memory_requirements_checked = true;
2034 }
2035}
2036
2037void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
2038 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002039 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002040}
2041
2042void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002043 const VkBufferMemoryRequirementsInfo2 *pInfo,
2044 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002045 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002046}
2047
2048void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002049 const VkBufferMemoryRequirementsInfo2 *pInfo,
2050 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002051 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002052}
2053
Spencer Fricke6c127102020-04-16 06:25:20 -07002054void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002055 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002056 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002057 IMAGE_STATE *image_state = GetImageState(image);
2058 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002059 if (plane_info != nullptr) {
2060 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002061 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002062 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002063 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002064 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002065 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002066 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002067 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002068 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002069 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002070 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002071 }
locke-lunargd556cc32019-09-17 01:21:23 -06002072 }
2073}
2074
2075void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
2076 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002077 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002078}
2079
2080void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
2081 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002082 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002083}
2084
2085void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
2086 const VkImageMemoryRequirementsInfo2 *pInfo,
2087 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002088 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002089}
2090
2091static void RecordGetImageSparseMemoryRequirementsState(IMAGE_STATE *image_state,
2092 VkSparseImageMemoryRequirements *sparse_image_memory_requirements) {
2093 image_state->sparse_requirements.emplace_back(*sparse_image_memory_requirements);
2094 if (sparse_image_memory_requirements->formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
2095 image_state->sparse_metadata_required = true;
2096 }
2097}
2098
2099void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
2100 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
2101 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
2102 auto image_state = GetImageState(image);
2103 image_state->get_sparse_reqs_called = true;
2104 if (!pSparseMemoryRequirements) return;
2105 for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) {
2106 RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i]);
2107 }
2108}
2109
2110void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002111 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2112 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06002113 auto image_state = GetImageState(pInfo->image);
2114 image_state->get_sparse_reqs_called = true;
2115 if (!pSparseMemoryRequirements) return;
2116 for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) {
2117 assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it
2118 RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements);
2119 }
2120}
2121
2122void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002123 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2124 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06002125 auto image_state = GetImageState(pInfo->image);
2126 image_state->get_sparse_reqs_called = true;
2127 if (!pSparseMemoryRequirements) return;
2128 for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) {
2129 assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it
2130 RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements);
2131 }
2132}
2133
2134void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2135 const VkAllocationCallbacks *pAllocator) {
2136 if (!shaderModule) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002137 auto shader_module_state = GetShaderModuleState(shaderModule);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002138 shader_module_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002139 shaderModuleMap.erase(shaderModule);
2140}
2141
2142void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2143 const VkAllocationCallbacks *pAllocator) {
2144 if (!pipeline) return;
2145 PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002146 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002147 pipeline_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002148 pipelineMap.erase(pipeline);
2149}
2150
2151void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2152 const VkAllocationCallbacks *pAllocator) {
2153 if (!pipelineLayout) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002154 auto pipeline_layout_state = GetPipelineLayout(pipelineLayout);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002155 pipeline_layout_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002156 pipelineLayoutMap.erase(pipelineLayout);
2157}
2158
2159void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2160 const VkAllocationCallbacks *pAllocator) {
2161 if (!sampler) return;
2162 SAMPLER_STATE *sampler_state = GetSamplerState(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002163 // Any bound cmd buffers are now invalid
2164 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002165 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2166 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2167 custom_border_color_sampler_count--;
2168 }
2169
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002170 sampler_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002171 }
2172 samplerMap.erase(sampler);
2173}
2174
2175void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2176 const VkAllocationCallbacks *pAllocator) {
2177 if (!descriptorSetLayout) return;
2178 auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout);
2179 if (layout_it != descriptorSetLayoutMap.end()) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002180 layout_it->second.get()->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002181 descriptorSetLayoutMap.erase(layout_it);
2182 }
2183}
2184
2185void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2186 const VkAllocationCallbacks *pAllocator) {
2187 if (!descriptorPool) return;
2188 DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002189 if (desc_pool_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002190 // Free sets that were in this pool
John Zulauf79f06582021-02-27 18:38:39 -07002191 for (auto *ds : desc_pool_state->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -06002192 FreeDescriptorSet(ds);
2193 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002194 desc_pool_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002195 descriptorPoolMap.erase(descriptorPool);
2196 }
2197}
2198
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002199// Free all command buffers in given list, removing all references/links to them using CMD_BUFFER_STATE::Reset
locke-lunargd556cc32019-09-17 01:21:23 -06002200void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count,
2201 const VkCommandBuffer *command_buffers) {
2202 for (uint32_t i = 0; i < command_buffer_count; i++) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002203 auto cb_state = Get<CMD_BUFFER_STATE>(command_buffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002204 // Remove references to command buffer's state and delete
2205 if (cb_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002206 cb_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002207 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002208 // Remove CBState from CB map
2209 pool_state->commandBuffers.erase(command_buffers[i]);
2210 commandBufferMap.erase(command_buffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002211 }
2212}
2213
2214void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2215 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002216 auto pool = GetCommandPoolState(commandPool);
2217 FreeCommandBufferStates(pool, commandBufferCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06002218}
2219
2220void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2221 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2222 VkResult result) {
2223 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002224 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -06002225 commandPoolMap[*pCommandPool] = std::make_shared<COMMAND_POOL_STATE>(*pCommandPool, pCreateInfo, queue_flags);
locke-lunargd556cc32019-09-17 01:21:23 -06002226}
2227
2228void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2229 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2230 VkResult result) {
2231 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002232
2233 uint32_t index_count = 0, n_perf_pass = 0;
2234 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002235 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002236 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002237 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002238
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002239 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002240 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2241 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2242 switch (counter.scope) {
2243 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002244 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002245 break;
2246 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002247 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002248 break;
2249 default:
2250 break;
2251 }
2252 }
2253
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002254 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002255 }
2256
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002257 queryPoolMap[*pQueryPool] =
2258 std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb);
locke-lunargd556cc32019-09-17 01:21:23 -06002259
2260 QueryObject query_obj{*pQueryPool, 0u};
2261 for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) {
2262 query_obj.query = i;
2263 queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN;
2264 }
2265}
2266
2267void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2268 const VkAllocationCallbacks *pAllocator) {
2269 if (!commandPool) return;
2270 COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool);
2271 // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers
2272 // "When a pool is destroyed, all command buffers allocated from the pool are freed."
2273 if (cp_state) {
2274 // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration.
2275 std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()};
2276 FreeCommandBufferStates(cp_state, static_cast<uint32_t>(cb_vec.size()), cb_vec.data());
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002277 cp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002278 commandPoolMap.erase(commandPool);
2279 }
2280}
2281
2282void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2283 VkCommandPoolResetFlags flags, VkResult result) {
2284 if (VK_SUCCESS != result) return;
2285 // Reset all of the CBs allocated from this pool
2286 auto command_pool_state = GetCommandPoolState(commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002287 for (auto cmd_buffer : command_pool_state->commandBuffers) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002288 auto cb_state = Get<CMD_BUFFER_STATE>(cmd_buffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002289 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002290 }
2291}
2292
2293void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2294 VkResult result) {
2295 for (uint32_t i = 0; i < fenceCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002296 auto fence_state = GetFenceState(pFences[i]);
2297 if (fence_state) {
2298 if (fence_state->scope == kSyncScopeInternal) {
2299 fence_state->state = FENCE_UNSIGNALED;
2300 } else if (fence_state->scope == kSyncScopeExternalTemporary) {
2301 fence_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06002302 }
2303 }
2304 }
2305}
2306
locke-lunargd556cc32019-09-17 01:21:23 -06002307void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2308 const VkAllocationCallbacks *pAllocator) {
2309 if (!framebuffer) return;
2310 FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002311 framebuffer_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002312 frameBufferMap.erase(framebuffer);
2313}
2314
2315void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2316 const VkAllocationCallbacks *pAllocator) {
2317 if (!renderPass) return;
2318 RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002319 rp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002320 renderPassMap.erase(renderPass);
2321}
2322
2323void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2324 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2325 if (VK_SUCCESS != result) return;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002326 fenceMap[*pFence] = std::make_shared<FENCE_STATE>(*pFence, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002327}
2328
2329bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2330 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2331 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002332 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002333 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2334 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2335 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2336 cgpl_state->pipe_state.reserve(count);
2337 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002338 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
2339 GetRenderPassShared(pCreateInfos[i].renderPass),
2340 GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002341 }
2342 return false;
2343}
2344
2345void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2346 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2347 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2348 VkResult result, void *cgpl_state_data) {
2349 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2350 // This API may create pipelines regardless of the return value
2351 for (uint32_t i = 0; i < count; i++) {
2352 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002353 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002354 pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]);
2355 }
2356 }
2357 cgpl_state->pipe_state.clear();
2358}
2359
2360bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2361 const VkComputePipelineCreateInfo *pCreateInfos,
2362 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002363 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002364 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2365 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2366 ccpl_state->pipe_state.reserve(count);
2367 for (uint32_t i = 0; i < count; i++) {
2368 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002369 ccpl_state->pipe_state.push_back(
2370 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002371 }
2372 return false;
2373}
2374
2375void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2376 const VkComputePipelineCreateInfo *pCreateInfos,
2377 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2378 VkResult result, void *ccpl_state_data) {
2379 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2380
2381 // This API may create pipelines regardless of the return value
2382 for (uint32_t i = 0; i < count; i++) {
2383 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002384 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002385 pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]);
2386 }
2387 }
2388 ccpl_state->pipe_state.clear();
2389}
2390
2391bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2392 uint32_t count,
2393 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2394 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002395 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002396 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2397 crtpl_state->pipe_state.reserve(count);
2398 for (uint32_t i = 0; i < count; i++) {
2399 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002400 crtpl_state->pipe_state.push_back(
2401 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002402 }
2403 return false;
2404}
2405
2406void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2407 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2408 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2409 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2410 // This API may create pipelines regardless of the return value
2411 for (uint32_t i = 0; i < count; i++) {
2412 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002413 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002414 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
2415 }
2416 }
2417 crtpl_state->pipe_state.clear();
2418}
2419
sourav parmarcd5fb182020-07-17 12:58:44 -07002420bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2421 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002422 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2423 const VkAllocationCallbacks *pAllocator,
2424 VkPipeline *pPipelines, void *crtpl_state_data) const {
2425 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2426 crtpl_state->pipe_state.reserve(count);
2427 for (uint32_t i = 0; i < count; i++) {
2428 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002429 crtpl_state->pipe_state.push_back(
2430 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002431 }
2432 return false;
2433}
2434
sourav parmarcd5fb182020-07-17 12:58:44 -07002435void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2436 VkPipelineCache pipelineCache, uint32_t count,
2437 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2438 const VkAllocationCallbacks *pAllocator,
2439 VkPipeline *pPipelines, VkResult result,
2440 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002441 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2442 // This API may create pipelines regardless of the return value
2443 for (uint32_t i = 0; i < count; i++) {
2444 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002445 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002446 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
2447 }
2448 }
2449 crtpl_state->pipe_state.clear();
2450}
2451
locke-lunargd556cc32019-09-17 01:21:23 -06002452void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2453 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2454 VkResult result) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002455 samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002456 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2457 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002458 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002459 }
locke-lunargd556cc32019-09-17 01:21:23 -06002460}
2461
2462void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2463 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2464 const VkAllocationCallbacks *pAllocator,
2465 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2466 if (VK_SUCCESS != result) return;
2467 descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout);
2468}
2469
locke-lunargd556cc32019-09-17 01:21:23 -06002470void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2471 const VkAllocationCallbacks *pAllocator,
2472 VkPipelineLayout *pPipelineLayout, VkResult result) {
2473 if (VK_SUCCESS != result) return;
2474
Jeremy Gebbene6e45542021-08-05 16:39:49 -06002475 pipelineLayoutMap[*pPipelineLayout] = std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002476}
2477
2478void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2479 const VkAllocationCallbacks *pAllocator,
2480 VkDescriptorPool *pDescriptorPool, VkResult result) {
2481 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002482 descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002483}
2484
2485void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2486 VkDescriptorPoolResetFlags flags, VkResult result) {
2487 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002488 DESCRIPTOR_POOL_STATE *pool = GetDescriptorPoolState(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002489 // TODO: validate flags
2490 // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet
John Zulauf79f06582021-02-27 18:38:39 -07002491 for (auto *ds : pool->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -06002492 FreeDescriptorSet(ds);
2493 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002494 pool->sets.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06002495 // Reset available count for each type and available sets for this pool
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002496 for (auto it = pool->availableDescriptorTypeCount.begin(); it != pool->availableDescriptorTypeCount.end(); ++it) {
2497 pool->availableDescriptorTypeCount[it->first] = pool->maxDescriptorTypeCount[it->first];
locke-lunargd556cc32019-09-17 01:21:23 -06002498 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002499 pool->availableSets = pool->maxSets;
locke-lunargd556cc32019-09-17 01:21:23 -06002500}
2501
2502bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2503 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002504 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002505 // Always update common data
2506 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2507 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2508 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2509
2510 return false;
2511}
2512
2513// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2514void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2515 VkDescriptorSet *pDescriptorSets, VkResult result,
2516 void *ads_state_data) {
2517 if (VK_SUCCESS != result) return;
2518 // All the updates are contained in a single cvdescriptorset function
2519 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2520 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2521 PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state);
2522}
2523
2524void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2525 const VkDescriptorSet *pDescriptorSets) {
2526 DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool);
2527 // Update available descriptor sets in pool
2528 pool_state->availableSets += count;
2529
2530 // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap
2531 for (uint32_t i = 0; i < count; ++i) {
2532 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
2533 auto descriptor_set = setMap[pDescriptorSets[i]].get();
2534 uint32_t type_index = 0, descriptor_count = 0;
2535 for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) {
2536 type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j));
2537 descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j);
2538 pool_state->availableDescriptorTypeCount[type_index] += descriptor_count;
2539 }
2540 FreeDescriptorSet(descriptor_set);
2541 pool_state->sets.erase(descriptor_set);
2542 }
2543 }
2544}
2545
2546void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2547 const VkWriteDescriptorSet *pDescriptorWrites,
2548 uint32_t descriptorCopyCount,
2549 const VkCopyDescriptorSet *pDescriptorCopies) {
2550 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2551 pDescriptorCopies);
2552}
2553
2554void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
2555 VkCommandBuffer *pCommandBuffer, VkResult result) {
2556 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002557 auto pool = GetCommandPoolShared(pCreateInfo->commandPool);
2558 if (pool) {
locke-lunargd556cc32019-09-17 01:21:23 -06002559 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
2560 // Add command buffer to its commandPool map
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002561 pool->commandBuffers.insert(pCommandBuffer[i]);
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002562 commandBufferMap[pCommandBuffer[i]] = CreateCmdBufferState(pCommandBuffer[i], pCreateInfo, pool);
locke-lunargfc78e932020-11-19 17:06:24 -07002563 }
2564 }
2565}
2566
locke-lunargd556cc32019-09-17 01:21:23 -06002567void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2568 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002569 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002570 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002571
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002572 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002573}
2574
2575void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002576 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002577 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002578
2579 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002580}
2581
2582void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2583 VkResult result) {
2584 if (VK_SUCCESS == result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002585 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002586 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002587 }
2588}
2589
2590CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2591 // initially assume everything is static state
2592 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2593
2594 if (ds) {
2595 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002596 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002597 }
2598 }
locke-lunargd556cc32019-09-17 01:21:23 -06002599 return flags;
2600}
2601
2602// Validation cache:
2603// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002604
2605void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2606 VkPipeline pipeline) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002607 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002608 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002609 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002610
2611 auto pipe_state = GetPipelineState(pipeline);
2612 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002613 const auto &create_info = pipe_state->create_info.graphics;
2614 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2615 const auto *viewport_state = create_info.pViewportState;
2616 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002617 cb_state->status &= ~cb_state->static_status;
Jeremy Gebben11af9792021-08-20 10:20:09 -06002618 cb_state->static_status = MakeStaticStateMask(dynamic_state->ptr());
locke-lunargd556cc32019-09-17 01:21:23 -06002619 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002620 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002621
2622 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002623 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2624 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002625 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002626 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002627 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002628 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002629 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002630 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002631
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002632 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002633 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2634 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2635 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002636 if (!has_dynamic_viewport_count) {
2637 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002638 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002639 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2640 // should become = ~uint32_t(0) if the other interpretation is correct.
2641 }
2642 }
2643 if (!has_dynamic_scissor_count) {
2644 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002645 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002646 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2647 // should become = ~uint32_t(0) if the other interpretation is correct.
2648 }
2649 }
locke-lunargd556cc32019-09-17 01:21:23 -06002650 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002651 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2652 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002653 if (!disabled[command_buffer_state]) {
2654 cb_state->AddChild(pipe_state);
2655 }
locke-lunargb8be8222020-10-20 00:34:37 -06002656 for (auto &slot : pipe_state->active_slots) {
2657 for (auto &req : slot.second) {
2658 for (auto &sampler : req.second.samplers_used_by_image) {
2659 for (auto &des : sampler) {
2660 des.second = nullptr;
2661 }
2662 }
2663 }
2664 }
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002665 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
locke-lunargd556cc32019-09-17 01:21:23 -06002666}
2667
2668void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2669 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002670 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002671 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002672 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2673 cb_state->viewportMask |= bits;
2674 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002675
2676 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2677 for (size_t i = 0; i < viewportCount; ++i) {
2678 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2679 }
locke-lunargd556cc32019-09-17 01:21:23 -06002680}
2681
2682void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2683 uint32_t exclusiveScissorCount,
2684 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002685 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002686 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002687 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2688 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002689}
2690
2691void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2692 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002693 if (disabled[command_buffer_state]) return;
2694
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002695 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002696 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002697
2698 if (imageView != VK_NULL_HANDLE) {
2699 auto view_state = GetImageViewState(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002700 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002701 }
2702}
2703
2704void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2705 uint32_t viewportCount,
2706 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002707 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002708 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002709 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2710 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002711}
2712
2713void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2714 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2715 const VkAllocationCallbacks *pAllocator,
2716 VkAccelerationStructureNV *pAccelerationStructure,
2717 VkResult result) {
2718 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002719 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002720
2721 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002722 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002723 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002724 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002725 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2726
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002727 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002728 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002729 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002730 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2731 &as_state->build_scratch_memory_requirements);
2732
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002733 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002734 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002735 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002736 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2737 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002738 as_state->allocator = pAllocator;
locke-lunargd556cc32019-09-17 01:21:23 -06002739 accelerationStructureMap[*pAccelerationStructure] = std::move(as_state);
2740}
2741
Jeff Bolz95176d02020-04-01 00:36:16 -05002742void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2743 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2744 const VkAllocationCallbacks *pAllocator,
2745 VkAccelerationStructureKHR *pAccelerationStructure,
2746 VkResult result) {
2747 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002748 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002749 as_state->allocator = pAllocator;
sourav parmarcd5fb182020-07-17 12:58:44 -07002750 accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state);
Jeff Bolz95176d02020-04-01 00:36:16 -05002751}
2752
sourav parmarcd5fb182020-07-17 12:58:44 -07002753void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2754 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2755 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002756 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002757 if (cb_state == nullptr) {
2758 return;
2759 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002760 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002761 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002762 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002763 if (dst_as_state != nullptr) {
2764 dst_as_state->built = true;
2765 dst_as_state->build_info_khr.initialize(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002766 if (!disabled[command_buffer_state]) {
2767 cb_state->AddChild(dst_as_state);
2768 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002769 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002770 if (!disabled[command_buffer_state]) {
2771 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2772 if (src_as_state != nullptr) {
2773 cb_state->AddChild(src_as_state);
2774 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002775 }
2776 }
2777 cb_state->hasBuildAccelerationStructureCmd = true;
2778}
2779
2780void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2781 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2782 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2783 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002784 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002785 if (cb_state == nullptr) {
2786 return;
2787 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002788 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002789 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002790 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002791 if (dst_as_state != nullptr) {
2792 dst_as_state->built = true;
2793 dst_as_state->build_info_khr.initialize(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002794 if (!disabled[command_buffer_state]) {
2795 cb_state->AddChild(dst_as_state);
2796 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002797 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002798 if (!disabled[command_buffer_state]) {
2799 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2800 if (src_as_state != nullptr) {
2801 cb_state->AddChild(src_as_state);
2802 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002803 }
2804 }
2805 cb_state->hasBuildAccelerationStructureCmd = true;
2806}
locke-lunargd556cc32019-09-17 01:21:23 -06002807void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002808 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002809 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002810 if (as_state != nullptr) {
2811 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2812 as_state->memory_requirements = *pMemoryRequirements;
2813 as_state->memory_requirements_checked = true;
2814 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2815 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2816 as_state->build_scratch_memory_requirements_checked = true;
2817 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2818 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2819 as_state->update_scratch_memory_requirements_checked = true;
2820 }
2821 }
2822}
2823
sourav parmarcd5fb182020-07-17 12:58:44 -07002824void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2825 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002826 if (VK_SUCCESS != result) return;
2827 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002828 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002829
sourav parmarcd5fb182020-07-17 12:58:44 -07002830 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002831 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002832 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002833 auto mem_state = GetDevMemShared(info.memory);
2834 if (mem_state) {
2835 as_state->SetMemBinding(mem_state, info.memoryOffset);
2836 }
locke-lunargd556cc32019-09-17 01:21:23 -06002837
2838 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002839 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002840 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002841 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2842 }
2843 }
2844 }
2845}
2846
2847void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2848 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2849 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002850 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002851 if (cb_state == nullptr) {
2852 return;
2853 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002854 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002855
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002856 auto *dst_as_state = GetAccelerationStructureStateNV(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002857 if (dst_as_state != nullptr) {
2858 dst_as_state->built = true;
2859 dst_as_state->build_info.initialize(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002860 if (!disabled[command_buffer_state]) {
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002861 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002862 }
locke-lunargd556cc32019-09-17 01:21:23 -06002863 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002864 if (!disabled[command_buffer_state]) {
2865 auto *src_as_state = GetAccelerationStructureStateNV(src);
2866 if (src_as_state != nullptr) {
2867 cb_state->AddChild(src_as_state);
2868 }
locke-lunargd556cc32019-09-17 01:21:23 -06002869 }
2870 cb_state->hasBuildAccelerationStructureCmd = true;
2871}
2872
2873void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2874 VkAccelerationStructureNV dst,
2875 VkAccelerationStructureNV src,
2876 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002877 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002878 if (cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002879 ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src);
2880 ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002881 if (!disabled[command_buffer_state]) {
2882 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2883 }
locke-lunargd556cc32019-09-17 01:21:23 -06002884 if (dst_as_state != nullptr && src_as_state != nullptr) {
2885 dst_as_state->built = true;
2886 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002887 }
2888 }
2889}
2890
Jeff Bolz95176d02020-04-01 00:36:16 -05002891void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2892 VkAccelerationStructureKHR accelerationStructure,
2893 const VkAllocationCallbacks *pAllocator) {
locke-lunargd556cc32019-09-17 01:21:23 -06002894 if (!accelerationStructure) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002895 auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002896 if (as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002897 as_state->Destroy();
sourav parmarcd5fb182020-07-17 12:58:44 -07002898 accelerationStructureMap_khr.erase(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002899 }
2900}
2901
Jeff Bolz95176d02020-04-01 00:36:16 -05002902void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2903 VkAccelerationStructureNV accelerationStructure,
2904 const VkAllocationCallbacks *pAllocator) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002905 if (!accelerationStructure) return;
2906 auto *as_state = GetAccelerationStructureStateNV(accelerationStructure);
2907 if (as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002908 as_state->Destroy();
sourav parmarcd5fb182020-07-17 12:58:44 -07002909 accelerationStructureMap.erase(accelerationStructure);
2910 }
Jeff Bolz95176d02020-04-01 00:36:16 -05002911}
2912
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002913void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2914 uint32_t viewportCount,
2915 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002916 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002917 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002918}
2919
locke-lunargd556cc32019-09-17 01:21:23 -06002920void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002921 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002922 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002923}
2924
2925void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2926 uint16_t lineStipplePattern) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002927 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002928 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002929}
2930
2931void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2932 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002933 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002934 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002935}
2936
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002937void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2938 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002939 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002940 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002941 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2942 cb_state->scissorMask |= bits;
2943 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002944}
2945
locke-lunargd556cc32019-09-17 01:21:23 -06002946void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002947 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002948 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002949}
2950
2951void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2952 float maxDepthBounds) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002953 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002954 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002955}
2956
2957void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2958 uint32_t compareMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002959 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002960 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002961}
2962
2963void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2964 uint32_t writeMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002965 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002966 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002967}
2968
2969void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2970 uint32_t reference) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002971 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002972 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002973}
2974
locke-lunargd556cc32019-09-17 01:21:23 -06002975
2976// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2977void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2978 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2979 uint32_t firstSet, uint32_t setCount,
2980 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2981 const uint32_t *pDynamicOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002982 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002983 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
locke-lunargd556cc32019-09-17 01:21:23 -06002984 auto pipeline_layout = GetPipelineLayout(layout);
2985
2986 // Resize binding arrays
2987 uint32_t last_set_index = firstSet + setCount - 1;
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002988 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2989 if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) {
2990 cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06002991 }
2992
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002993 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr,
2994 dynamicOffsetCount, pDynamicOffsets);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002995 cb_state->lastBound[lv_bind_point].pipeline_layout = layout;
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002996 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002997}
2998
locke-lunargd556cc32019-09-17 01:21:23 -06002999void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
3000 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
3001 uint32_t set, uint32_t descriptorWriteCount,
3002 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003003 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003004 auto pipeline_layout = GetPipelineLayout(layout);
3005 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout, set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06003006}
3007
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06003008void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
3009 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
3010 const void *pValues) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003011 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06003012 if (cb_state != nullptr) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003013 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003014 cb_state->ResetPushConstantDataIfIncompatible(GetPipelineLayout(layout));
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06003015
3016 auto &push_constant_data = cb_state->push_constant_data;
3017 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
3018 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06003019 cb_state->push_constant_pipeline_layout_set = layout;
3020
3021 auto flags = stageFlags;
3022 uint32_t bit_shift = 0;
3023 while (flags) {
3024 if (flags & 1) {
3025 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
3026 const auto it = cb_state->push_constant_data_update.find(flag);
3027
3028 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06003029 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06003030 }
3031 }
3032 flags = flags >> 1;
3033 ++bit_shift;
3034 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06003035 }
3036}
3037
locke-lunargd556cc32019-09-17 01:21:23 -06003038void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3039 VkIndexType indexType) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003040 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003041
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003042 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003043 cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer);
3044 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06003045 cb_state->index_buffer_binding.offset = offset;
3046 cb_state->index_buffer_binding.index_type = indexType;
3047 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003048 if (!disabled[command_buffer_state]) {
3049 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state.get());
3050 }
locke-lunargd556cc32019-09-17 01:21:23 -06003051}
3052
3053void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
3054 uint32_t bindingCount, const VkBuffer *pBuffers,
3055 const VkDeviceSize *pOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003056 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003057 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06003058
3059 uint32_t end = firstBinding + bindingCount;
3060 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
3061 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
3062 }
3063
3064 for (uint32_t i = 0; i < bindingCount; ++i) {
3065 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07003066 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003067 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06003068 vertex_buffer_binding.size = VK_WHOLE_SIZE;
3069 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06003070 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003071 if (pBuffers[i] && !disabled[command_buffer_state]) {
3072 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Jeff Bolz165818a2020-05-08 11:19:03 -05003073 }
locke-lunargd556cc32019-09-17 01:21:23 -06003074 }
3075}
3076
3077void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
3078 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003079 if (disabled[command_buffer_state]) return;
3080
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003081 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003082 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06003083}
3084
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003085void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3086 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003087 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3088 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003089}
3090
3091void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3092 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003093 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003094 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3095
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003096 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
3097 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003098}
3099
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003100void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3101 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003102 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3103 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003104}
3105
3106void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3107 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003108 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3109 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003110}
3111
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003112void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3113 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
3114 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3115 uint32_t bufferMemoryBarrierCount,
3116 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3117 uint32_t imageMemoryBarrierCount,
3118 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003119 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3120 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
3121 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3122 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003123}
3124
3125void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3126 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003127 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3128 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
Jeremy Gebben79649152021-06-22 14:46:24 -06003129 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003130 cb_state->RecordBarriers(pDependencyInfos[i]);
Jeremy Gebben79649152021-06-22 14:46:24 -06003131 }
3132}
3133
3134void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3135 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3136 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3137 uint32_t bufferMemoryBarrierCount,
3138 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3139 uint32_t imageMemoryBarrierCount,
3140 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003141 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3142 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3143 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3144 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003145}
3146
3147void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3148 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003149 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3150 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3151 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003152}
3153
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003154QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex,
3155 uint32_t perfPass) const {
3156 QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass);
locke-lunargd556cc32019-09-17 01:21:23 -06003157
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003158 auto iter = localQueryToStateMap->find(query);
3159 if (iter != localQueryToStateMap->end()) return iter->second;
Jeff Bolz310775c2019-10-09 00:46:33 -05003160
Jeff Bolz310775c2019-10-09 00:46:33 -05003161 return QUERYSTATE_UNKNOWN;
locke-lunargd556cc32019-09-17 01:21:23 -06003162}
3163
locke-lunargd556cc32019-09-17 01:21:23 -06003164void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3165 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003166 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003167
locke-lunargd556cc32019-09-17 01:21:23 -06003168 QueryObject query = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003169 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003170 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003171 if (!disabled[query_validation]) {
3172 cb_state->BeginQuery(query);
3173 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003174 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003175 auto pool_state = GetQueryPoolState(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003176 cb_state->AddChild(pool_state);
3177 }
locke-lunargd556cc32019-09-17 01:21:23 -06003178}
3179
3180void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003181 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003182 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003183 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003184 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003185 if (!disabled[query_validation]) {
3186 cb_state->EndQuery(query_obj);
3187 }
3188 if (!disabled[command_buffer_state]) {
3189 auto pool_state = GetQueryPoolState(query_obj.pool);
3190 cb_state->AddChild(pool_state);
3191 }
locke-lunargd556cc32019-09-17 01:21:23 -06003192}
3193
3194void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3195 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003196 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003197 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003198
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003199 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003200 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003201
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003202 if (!disabled[command_buffer_state]) {
3203 auto pool_state = GetQueryPoolState(queryPool);
3204 cb_state->AddChild(pool_state);
3205 }
locke-lunargd556cc32019-09-17 01:21:23 -06003206}
3207
3208void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3209 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3210 VkDeviceSize dstOffset, VkDeviceSize stride,
3211 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003212 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3213
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003214 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003215 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
locke-lunargd556cc32019-09-17 01:21:23 -06003216 auto dst_buff_state = GetBufferState(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003217 cb_state->AddChild(dst_buff_state);
Jeff Bolzadbfa852019-10-04 13:53:30 -05003218 auto pool_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003219 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003220}
3221
3222void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3223 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003224 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3225 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003226}
3227
3228void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3229 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3230 uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003231 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3232 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003233}
3234
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003235void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3236 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3237 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3238 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003239 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003240 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003241 if (!disabled[command_buffer_state]) {
3242 auto pool_state = GetQueryPoolState(queryPool);
3243 cb_state->AddChild(pool_state);
3244 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003245 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003246}
3247
locke-lunargd556cc32019-09-17 01:21:23 -06003248void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3249 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3250 VkResult result) {
3251 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003252
Jeremy Gebben88f58142021-06-01 10:07:52 -06003253 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003254 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003255 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003256
locke-lunargd556cc32019-09-17 01:21:23 -06003257 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003258 views[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003259 }
3260 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003261
3262 frameBufferMap[*pFramebuffer] = std::make_shared<FRAMEBUFFER_STATE>(
3263 *pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass), std::move(views));
locke-lunargd556cc32019-09-17 01:21:23 -06003264}
3265
locke-lunargd556cc32019-09-17 01:21:23 -06003266void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3267 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3268 VkResult result) {
3269 if (VK_SUCCESS != result) return;
Jeremy Gebben88f58142021-06-01 10:07:52 -06003270 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06003271}
3272
Mike Schuchardt2df08912020-12-15 16:28:09 -08003273void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003274 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3275 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003276 if (VK_SUCCESS != result) return;
3277
3278 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
Tony-LunarG977448c2019-12-02 14:52:02 -07003279}
3280
Mike Schuchardt2df08912020-12-15 16:28:09 -08003281void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003282 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3283 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003284 if (VK_SUCCESS != result) return;
3285
3286 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
Tony-LunarG977448c2019-12-02 14:52:02 -07003287}
3288
locke-lunargd556cc32019-09-17 01:21:23 -06003289void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3290 const VkRenderPassBeginInfo *pRenderPassBegin,
3291 VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003292 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3293 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003294}
3295
3296void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3297 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003298 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003299 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3300 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003301}
3302
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003303void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3304 uint32_t counterBufferCount,
3305 const VkBuffer *pCounterBuffers,
3306 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003307 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003308
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003309 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003310 cb_state->transform_feedback_active = true;
3311}
3312
3313void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3314 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3315 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003316 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003317
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003318 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003319 cb_state->transform_feedback_active = false;
3320}
3321
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003322void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3323 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06003324 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003325
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003326 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003327 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003328 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3329 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003330}
3331
3332void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06003333 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003334
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003335 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003336 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003337 cb_state->conditional_rendering_inside_render_pass = false;
3338 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003339}
3340
Tony-LunarG977448c2019-12-02 14:52:02 -07003341void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3342 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003343 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003344 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3345 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003346}
3347
locke-lunargd556cc32019-09-17 01:21:23 -06003348
3349void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003350 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3351 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003352}
3353
3354void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003355 const VkSubpassBeginInfo *pSubpassBeginInfo,
3356 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003357 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3358 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003359}
3360
Tony-LunarG977448c2019-12-02 14:52:02 -07003361void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003362 const VkSubpassBeginInfo *pSubpassBeginInfo,
3363 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003364 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003365 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003366}
3367
3368void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003369 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3370 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003371}
3372
3373void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003374 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003375 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3376 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
locke-lunargd556cc32019-09-17 01:21:23 -06003377}
3378
Tony-LunarG977448c2019-12-02 14:52:02 -07003379void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003380 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003381 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3382 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003383}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003384
locke-lunargd556cc32019-09-17 01:21:23 -06003385void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3386 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003387 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003388
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003389 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003390}
3391
3392void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3393 VkFlags flags, void **ppData, VkResult result) {
3394 if (VK_SUCCESS != result) return;
3395 RecordMappedMemory(mem, offset, size, ppData);
3396}
3397
3398void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
3399 auto mem_info = GetDevMemState(mem);
3400 if (mem_info) {
3401 mem_info->mapped_range = MemRange();
3402 mem_info->p_driver_data = nullptr;
3403 }
3404}
3405
3406void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben8ee02af2021-07-16 10:15:55 -06003407 auto image_state = GetShared<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003408 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003409 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3410 // See: VUID-vkGetImageSubresourceLayout-image-01895
3411 image_state->fragment_encoder =
3412 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003413 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003414 if (swapchain_info) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003415 auto swapchain = GetShared<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003416 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003417 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003418
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003419 if (!swapchain_image.fake_base_address) {
3420 auto size = image_state->fragment_encoder->TotalSize();
3421 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003422 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003423 // All images bound to this swapchain and index are aliases
3424 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003425 }
3426 } else {
3427 // Track bound memory range information
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003428 auto mem_info = GetDevMemShared(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003429 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003430 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003431 }
locke-lunargd556cc32019-09-17 01:21:23 -06003432 }
locke-lunargd556cc32019-09-17 01:21:23 -06003433 }
3434}
3435
3436void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3437 VkDeviceSize memoryOffset, VkResult result) {
3438 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003439 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003440 bind_info.image = image;
3441 bind_info.memory = mem;
3442 bind_info.memoryOffset = memoryOffset;
3443 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003444}
3445
3446void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003447 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003448 if (VK_SUCCESS != result) return;
3449 for (uint32_t i = 0; i < bindInfoCount; i++) {
3450 UpdateBindImageMemoryState(pBindInfos[i]);
3451 }
3452}
3453
3454void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003455 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003456 if (VK_SUCCESS != result) return;
3457 for (uint32_t i = 0; i < bindInfoCount; i++) {
3458 UpdateBindImageMemoryState(pBindInfos[i]);
3459 }
3460}
3461
3462void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
3463 auto event_state = GetEventState(event);
3464 if (event_state) {
3465 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3466 }
locke-lunargd556cc32019-09-17 01:21:23 -06003467}
3468
3469void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3470 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3471 VkResult result) {
3472 if (VK_SUCCESS != result) return;
3473 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3474 pImportSemaphoreFdInfo->flags);
3475}
3476
3477void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003478 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003479 SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore);
Mike Schuchardt2df08912020-12-15 16:28:09 -08003480 if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003481 // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference
3482 semaphore_state->scope = kSyncScopeExternalPermanent;
3483 }
3484}
3485
3486#ifdef VK_USE_PLATFORM_WIN32_KHR
3487void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3488 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3489 if (VK_SUCCESS != result) return;
3490 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3491 pImportSemaphoreWin32HandleInfo->flags);
3492}
3493
3494void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3495 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3496 HANDLE *pHandle, VkResult result) {
3497 if (VK_SUCCESS != result) return;
3498 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3499}
3500
3501void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3502 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3503 if (VK_SUCCESS != result) return;
3504 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3505 pImportFenceWin32HandleInfo->flags);
3506}
3507
3508void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3509 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3510 HANDLE *pHandle, VkResult result) {
3511 if (VK_SUCCESS != result) return;
3512 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3513}
3514#endif
3515
3516void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3517 VkResult result) {
3518 if (VK_SUCCESS != result) return;
3519 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3520}
3521
Mike Schuchardt2df08912020-12-15 16:28:09 -08003522void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3523 VkFenceImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06003524 FENCE_STATE *fence_node = GetFenceState(fence);
3525 if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003526 if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06003527 fence_node->scope == kSyncScopeInternal) {
3528 fence_node->scope = kSyncScopeExternalTemporary;
3529 } else {
3530 fence_node->scope = kSyncScopeExternalPermanent;
3531 }
3532 }
3533}
3534
3535void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3536 VkResult result) {
3537 if (VK_SUCCESS != result) return;
3538 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3539}
3540
Mike Schuchardt2df08912020-12-15 16:28:09 -08003541void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003542 FENCE_STATE *fence_state = GetFenceState(fence);
3543 if (fence_state) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003544 if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003545 // Export with reference transference becomes external
3546 fence_state->scope = kSyncScopeExternalPermanent;
3547 } else if (fence_state->scope == kSyncScopeInternal) {
3548 // Export with copy transference has a side effect of resetting the fence
3549 fence_state->state = FENCE_UNSIGNALED;
3550 }
3551 }
3552}
3553
3554void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3555 VkResult result) {
3556 if (VK_SUCCESS != result) return;
3557 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3558}
3559
3560void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3561 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3562 if (VK_SUCCESS != result) return;
John Zulaufd5115702021-01-18 12:34:33 -07003563 const auto event = *pEvent;
Jeremy Gebbencbf22862021-03-03 12:01:22 -07003564 eventMap.emplace(event, std::make_shared<EVENT_STATE>(event, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003565}
3566
3567void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003568 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003569 SWAPCHAIN_NODE *old_swapchain_state) {
3570 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003571 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003572 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003573 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003574 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3575 surface_state->AddParent(swapchain.get());
3576 surface_state->swapchain = swapchain.get();
3577 swapchain->surface = std::move(surface_state);
3578 swapchainMap[*pSwapchain] = std::move(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003579 } else {
3580 surface_state->swapchain = nullptr;
3581 }
3582 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003583 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003584 if (old_swapchain_state) {
3585 old_swapchain_state->retired = true;
3586 }
3587 return;
3588}
3589
3590void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3591 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3592 VkResult result) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003593 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfo->surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003594 auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003595 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003596}
3597
3598void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3599 const VkAllocationCallbacks *pAllocator) {
3600 if (!swapchain) return;
3601 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003602 if (!swapchain_data) return;
John Zulauffaa7a522021-03-05 12:22:45 -07003603
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003604 swapchain_data->Destroy();
3605 swapchainMap.erase(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003606}
3607
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003608void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3609 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3610 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3611 VkResult result) {
3612 if (VK_SUCCESS != result) return;
3613 if (!pMode) return;
Jeremy Gebben5573a8c2021-06-04 08:55:10 -06003614 display_mode_map[*pMode] = std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice);
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003615}
3616
locke-lunargd556cc32019-09-17 01:21:23 -06003617void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
3618 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3619 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003620 auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]);
3621 if (semaphore_state) {
3622 semaphore_state->signaler.first = VK_NULL_HANDLE;
3623 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06003624 }
3625 }
3626
Tony-LunarG6f887e52021-07-27 11:23:14 -06003627 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003628 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3629 // 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
3630 // confused itself just as much.
3631 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3632 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3633 // Mark the image as having been released to the WSI
3634 auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003635 if (swapchain_data) {
3636 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003637 if (present_id_info) {
3638 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3639 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3640 }
3641 }
locke-lunargd556cc32019-09-17 01:21:23 -06003642 }
3643 }
3644 // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and
3645 // its semaphore waits) /never/ participate in any completion proof.
3646}
3647
3648void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3649 const VkSwapchainCreateInfoKHR *pCreateInfos,
3650 const VkAllocationCallbacks *pAllocator,
3651 VkSwapchainKHR *pSwapchains, VkResult result) {
3652 if (pCreateInfos) {
3653 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003654 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfos[i].surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003655 auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003656 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003657 }
3658 }
3659}
3660
3661void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3662 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003663 auto fence_state = GetFenceState(fence);
3664 if (fence_state && fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003665 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3666 // import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003667 fence_state->state = FENCE_INFLIGHT;
3668 fence_state->signaler.first = VK_NULL_HANDLE; // ANI isn't on a queue, so this can't participate in a completion proof.
locke-lunargd556cc32019-09-17 01:21:23 -06003669 }
3670
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003671 auto semaphore_state = GetSemaphoreState(semaphore);
3672 if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003673 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3674 // temporary import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003675 semaphore_state->signaled = true;
3676 semaphore_state->signaler.first = VK_NULL_HANDLE;
locke-lunargd556cc32019-09-17 01:21:23 -06003677 }
3678
3679 // Mark the image as acquired.
3680 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003681 if (swapchain_data) {
3682 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003683 }
3684}
3685
3686void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3687 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3688 VkResult result) {
3689 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3690 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3691}
3692
3693void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3694 uint32_t *pImageIndex, VkResult result) {
3695 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3696 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3697 pAcquireInfo->fence, pImageIndex);
3698}
3699
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003700std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3701 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3702}
3703
locke-lunargd556cc32019-09-17 01:21:23 -06003704void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
3705 VkPhysicalDevice *pPhysicalDevices, VkResult result) {
3706 if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) {
3707 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003708 physical_device_map.emplace(pPhysicalDevices[i], CreatePhysicalDeviceState(pPhysicalDevices[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06003709 }
3710 }
3711}
3712
3713// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003714static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003715 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003716}
3717
3718void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3719 uint32_t *pQueueFamilyPropertyCount,
3720 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003721 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3722 assert(pd_state);
3723 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003724}
3725
3726void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003727 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003728 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3729 assert(pd_state);
3730 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003731}
3732
3733void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003734 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003735 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3736 assert(pd_state);
3737 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003738}
3739void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3740 const VkAllocationCallbacks *pAllocator) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003741 if (!surface) return;
3742 auto surface_state = GetSurfaceState(surface);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003743 surface_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06003744 surface_map.erase(surface);
3745}
3746
3747void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003748 surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface);
locke-lunargd556cc32019-09-17 01:21:23 -06003749}
3750
3751void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3752 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3753 const VkAllocationCallbacks *pAllocator,
3754 VkSurfaceKHR *pSurface, VkResult result) {
3755 if (VK_SUCCESS != result) return;
3756 RecordVulkanSurface(pSurface);
3757}
3758
3759#ifdef VK_USE_PLATFORM_ANDROID_KHR
3760void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3761 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3762 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3763 VkResult result) {
3764 if (VK_SUCCESS != result) return;
3765 RecordVulkanSurface(pSurface);
3766}
3767#endif // VK_USE_PLATFORM_ANDROID_KHR
3768
3769#ifdef VK_USE_PLATFORM_IOS_MVK
3770void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3771 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3772 VkResult result) {
3773 if (VK_SUCCESS != result) return;
3774 RecordVulkanSurface(pSurface);
3775}
3776#endif // VK_USE_PLATFORM_IOS_MVK
3777
3778#ifdef VK_USE_PLATFORM_MACOS_MVK
3779void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3780 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3781 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3782 VkResult result) {
3783 if (VK_SUCCESS != result) return;
3784 RecordVulkanSurface(pSurface);
3785}
3786#endif // VK_USE_PLATFORM_MACOS_MVK
3787
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003788#ifdef VK_USE_PLATFORM_METAL_EXT
3789void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3790 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3791 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3792 VkResult result) {
3793 if (VK_SUCCESS != result) return;
3794 RecordVulkanSurface(pSurface);
3795}
3796#endif // VK_USE_PLATFORM_METAL_EXT
3797
locke-lunargd556cc32019-09-17 01:21:23 -06003798#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3799void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3800 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3801 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3802 VkResult result) {
3803 if (VK_SUCCESS != result) return;
3804 RecordVulkanSurface(pSurface);
3805}
3806#endif // VK_USE_PLATFORM_WAYLAND_KHR
3807
3808#ifdef VK_USE_PLATFORM_WIN32_KHR
3809void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3810 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3811 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3812 VkResult result) {
3813 if (VK_SUCCESS != result) return;
3814 RecordVulkanSurface(pSurface);
3815}
3816#endif // VK_USE_PLATFORM_WIN32_KHR
3817
3818#ifdef VK_USE_PLATFORM_XCB_KHR
3819void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3820 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3821 VkResult result) {
3822 if (VK_SUCCESS != result) return;
3823 RecordVulkanSurface(pSurface);
3824}
3825#endif // VK_USE_PLATFORM_XCB_KHR
3826
3827#ifdef VK_USE_PLATFORM_XLIB_KHR
3828void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3829 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3830 VkResult result) {
3831 if (VK_SUCCESS != result) return;
3832 RecordVulkanSurface(pSurface);
3833}
3834#endif // VK_USE_PLATFORM_XLIB_KHR
3835
Niklas Haas8b84af12020-04-19 22:20:11 +02003836void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3837 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3838 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3839 VkResult result) {
3840 if (VK_SUCCESS != result) return;
3841 RecordVulkanSurface(pSurface);
3842}
3843
locke-lunargd556cc32019-09-17 01:21:23 -06003844void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3845 VkSurfaceKHR surface,
3846 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3847 VkResult result) {
3848 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003849 auto physical_device_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003850 physical_device_state->surfaceCapabilities = *pSurfaceCapabilities;
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003851
3852 // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first
3853 physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003854}
3855
3856void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3857 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3858 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3859 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003860 auto physical_device_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003861 physical_device_state->surfaceCapabilities = pSurfaceCapabilities->surfaceCapabilities;
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003862
3863 // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first
3864 physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003865}
3866
3867void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3868 VkSurfaceKHR surface,
3869 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3870 VkResult result) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003871 auto physical_device_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003872 physical_device_state->surfaceCapabilities.minImageCount = pSurfaceCapabilities->minImageCount;
3873 physical_device_state->surfaceCapabilities.maxImageCount = pSurfaceCapabilities->maxImageCount;
3874 physical_device_state->surfaceCapabilities.currentExtent = pSurfaceCapabilities->currentExtent;
3875 physical_device_state->surfaceCapabilities.minImageExtent = pSurfaceCapabilities->minImageExtent;
3876 physical_device_state->surfaceCapabilities.maxImageExtent = pSurfaceCapabilities->maxImageExtent;
3877 physical_device_state->surfaceCapabilities.maxImageArrayLayers = pSurfaceCapabilities->maxImageArrayLayers;
3878 physical_device_state->surfaceCapabilities.supportedTransforms = pSurfaceCapabilities->supportedTransforms;
3879 physical_device_state->surfaceCapabilities.currentTransform = pSurfaceCapabilities->currentTransform;
3880 physical_device_state->surfaceCapabilities.supportedCompositeAlpha = pSurfaceCapabilities->supportedCompositeAlpha;
3881 physical_device_state->surfaceCapabilities.supportedUsageFlags = pSurfaceCapabilities->supportedUsageFlags;
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003882
3883 // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first
3884 physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003885}
3886
3887void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3888 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3889 VkBool32 *pSupported, VkResult result) {
3890 if (VK_SUCCESS != result) return;
3891 auto surface_state = GetSurfaceState(surface);
3892 surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE);
3893}
3894
3895void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3896 VkSurfaceKHR surface,
3897 uint32_t *pPresentModeCount,
3898 VkPresentModeKHR *pPresentModes,
3899 VkResult result) {
3900 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3901
3902 // TODO: This isn't quite right -- available modes may differ by surface AND physical device.
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003903 auto physical_device_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003904
3905 if (*pPresentModeCount) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003906 if (*pPresentModeCount > physical_device_state->present_modes.size()) {
locke-lunargd556cc32019-09-17 01:21:23 -06003907 physical_device_state->present_modes.resize(*pPresentModeCount);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003908 }
locke-lunargd556cc32019-09-17 01:21:23 -06003909 }
3910 if (pPresentModes) {
locke-lunargd556cc32019-09-17 01:21:23 -06003911 for (uint32_t i = 0; i < *pPresentModeCount; i++) {
3912 physical_device_state->present_modes[i] = pPresentModes[i];
3913 }
3914 }
3915}
3916
3917void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3918 uint32_t *pSurfaceFormatCount,
3919 VkSurfaceFormatKHR *pSurfaceFormats,
3920 VkResult result) {
3921 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3922
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003923 auto physical_device_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003924
3925 if (*pSurfaceFormatCount) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003926 if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) {
locke-lunargd556cc32019-09-17 01:21:23 -06003927 physical_device_state->surface_formats.resize(*pSurfaceFormatCount);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003928 }
locke-lunargd556cc32019-09-17 01:21:23 -06003929 }
3930 if (pSurfaceFormats) {
locke-lunargd556cc32019-09-17 01:21:23 -06003931 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3932 physical_device_state->surface_formats[i] = pSurfaceFormats[i];
3933 }
3934 }
3935}
3936
3937void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3938 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3939 uint32_t *pSurfaceFormatCount,
3940 VkSurfaceFormat2KHR *pSurfaceFormats,
3941 VkResult result) {
3942 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3943
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003944 auto physical_device_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003945 if (*pSurfaceFormatCount) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003946 if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) {
3947 physical_device_state->surface_formats.resize(*pSurfaceFormatCount);
3948 }
locke-lunargd556cc32019-09-17 01:21:23 -06003949 }
3950 if (pSurfaceFormats) {
locke-lunargd556cc32019-09-17 01:21:23 -06003951 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003952 physical_device_state->surface_formats[i] = pSurfaceFormats[i].surfaceFormat;
locke-lunargd556cc32019-09-17 01:21:23 -06003953 }
3954 }
3955}
3956
3957void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3958 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003959 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3960 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003961 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3962}
3963
3964void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003965 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3966 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003967 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3968}
3969
3970void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3971 const VkDebugUtilsLabelEXT *pLabelInfo) {
3972 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3973
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003974 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003975 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3976 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003977 cb_state->debug_label = LoggingLabel(pLabelInfo);
3978}
3979
3980void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003981 uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) {
locke-lunargd556cc32019-09-17 01:21:23 -06003982 if (NULL != pPhysicalDeviceGroupProperties) {
3983 for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) {
3984 for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) {
3985 VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j];
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003986
3987 physical_device_map.emplace(cur_phys_dev, CreatePhysicalDeviceState(cur_phys_dev));
locke-lunargd556cc32019-09-17 01:21:23 -06003988 }
3989 }
3990 }
3991}
3992
3993void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003994 VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
locke-lunargd556cc32019-09-17 01:21:23 -06003995 VkResult result) {
3996 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3997 RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
3998}
3999
4000void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08004001 VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
locke-lunargd556cc32019-09-17 01:21:23 -06004002 VkResult result) {
4003 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4004 RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
4005}
4006
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004007void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
4008 uint32_t queueFamilyIndex,
4009 uint32_t *pCounterCount,
4010 VkPerformanceCounterKHR *pCounters) {
4011 if (NULL == pCounters) return;
4012
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004013 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
4014 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004015
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004016 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
4017 queue_family_counters->counters.resize(*pCounterCount);
4018 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004019
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004020 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004021}
4022
4023void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
4024 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
4025 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
4026 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4027 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
4028}
4029
4030void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
4031 VkResult result) {
4032 if (result == VK_SUCCESS) performance_lock_acquired = true;
4033}
4034
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004035void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
4036 performance_lock_acquired = false;
4037 for (auto &cmd_buffer : commandBufferMap) {
4038 cmd_buffer.second->performance_lock_released = true;
4039 }
4040}
4041
locke-lunargd556cc32019-09-17 01:21:23 -06004042void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004043 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004044 const VkAllocationCallbacks *pAllocator) {
4045 if (!descriptorUpdateTemplate) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004046 auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
4047 template_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004048 desc_template_map.erase(descriptorUpdateTemplate);
4049}
4050
4051void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004052 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004053 const VkAllocationCallbacks *pAllocator) {
4054 if (!descriptorUpdateTemplate) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004055 auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
4056 template_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004057 desc_template_map.erase(descriptorUpdateTemplate);
4058}
4059
Mike Schuchardt2df08912020-12-15 16:28:09 -08004060void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4061 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
locke-lunargd556cc32019-09-17 01:21:23 -06004062 safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004063 auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004064 desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state);
4065}
4066
Mike Schuchardt2df08912020-12-15 16:28:09 -08004067void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
4068 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4069 const VkAllocationCallbacks *pAllocator,
4070 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
4071 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004072 if (VK_SUCCESS != result) return;
4073 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4074}
4075
4076void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08004077 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4078 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004079 if (VK_SUCCESS != result) return;
4080 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4081}
4082
4083void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004084 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004085 const void *pData) {
4086 auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate);
4087 if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) {
4088 assert(0);
4089 } else {
4090 const TEMPLATE_STATE *template_state = template_map_entry->second.get();
4091 // TODO: Record template push descriptor updates
4092 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
4093 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData);
4094 }
4095 }
4096}
4097
4098void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
4099 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4100 const void *pData) {
4101 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4102}
4103
4104void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004105 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004106 const void *pData) {
4107 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4108}
4109
Mike Schuchardt2df08912020-12-15 16:28:09 -08004110void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
4111 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4112 VkPipelineLayout layout, uint32_t set,
4113 const void *pData) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004114 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004115
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004116 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
locke-lunargd556cc32019-09-17 01:21:23 -06004117 const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
4118 if (template_state) {
4119 auto layout_data = GetPipelineLayout(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06004120 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004121 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004122 // Decode the template into a set of write updates
4123 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData,
4124 dsl->GetDescriptorSetLayout());
4125 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data, set,
4126 static_cast<uint32_t>(decoded_template.desc_writes.size()),
4127 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06004128 }
4129}
4130
4131void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
4132 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004133 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06004134 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004135 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004136 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06004137 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004138 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004139 }
4140}
4141
4142void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
4143 uint32_t *pPropertyCount,
4144 VkDisplayPlanePropertiesKHR *pProperties,
4145 VkResult result) {
4146 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4147 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4148}
4149
4150void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
4151 uint32_t *pPropertyCount,
4152 VkDisplayPlaneProperties2KHR *pProperties,
4153 VkResult result) {
4154 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4155 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4156}
4157
4158void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4159 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
4160 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004161 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004162 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004163 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004164}
4165
4166void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4167 uint32_t query, uint32_t index) {
4168 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004169 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004170 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004171 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004172}
4173
4174void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4175 VkSamplerYcbcrConversion ycbcr_conversion) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004176 VkFormatFeatureFlags format_features = 0;
4177
4178 if (create_info->format != VK_FORMAT_UNDEFINED) {
4179 format_features = GetPotentialFormatFeatures(create_info->format);
4180 } else if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
4181 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4182 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004183 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004184
4185 samplerYcbcrConversionMap[ycbcr_conversion] =
4186 std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features);
locke-lunargd556cc32019-09-17 01:21:23 -06004187}
4188
4189void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4190 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4191 const VkAllocationCallbacks *pAllocator,
4192 VkSamplerYcbcrConversion *pYcbcrConversion,
4193 VkResult result) {
4194 if (VK_SUCCESS != result) return;
4195 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4196}
4197
4198void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4199 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4200 const VkAllocationCallbacks *pAllocator,
4201 VkSamplerYcbcrConversion *pYcbcrConversion,
4202 VkResult result) {
4203 if (VK_SUCCESS != result) return;
4204 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4205}
4206
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004207void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004208 auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004209 ycbcr_state->Destroy();
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004210 samplerYcbcrConversionMap.erase(ycbcr_conversion);
4211}
4212
locke-lunargd556cc32019-09-17 01:21:23 -06004213void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4214 const VkAllocationCallbacks *pAllocator) {
4215 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004216 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004217}
4218
4219void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4220 VkSamplerYcbcrConversion ycbcrConversion,
4221 const VkAllocationCallbacks *pAllocator) {
4222 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004223 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004224}
4225
Tony-LunarG977448c2019-12-02 14:52:02 -07004226void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4227 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004228 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004229 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004230
4231 // Do nothing if the query pool has been destroyed.
4232 auto query_pool_state = GetQueryPoolState(queryPool);
4233 if (!query_pool_state) return;
4234
4235 // Reset the state of existing entries.
4236 QueryObject query_obj{queryPool, 0};
4237 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4238 for (uint32_t i = 0; i < max_query_count; ++i) {
4239 query_obj.query = firstQuery + i;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004240 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004241 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004242 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
4243 query_obj.perf_pass = pass_index;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004244 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004245 }
4246 }
locke-lunargd556cc32019-09-17 01:21:23 -06004247 }
4248}
4249
Tony-LunarG977448c2019-12-02 14:52:02 -07004250void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4251 uint32_t queryCount) {
4252 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4253}
4254
4255void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4256 uint32_t queryCount) {
4257 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4258}
4259
locke-lunargd556cc32019-09-17 01:21:23 -06004260void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
4261 const TEMPLATE_STATE *template_state, const void *pData) {
4262 // Translate the templated update into a normal update for validation...
4263 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4264 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4265 decoded_update.desc_writes.data(), 0, NULL);
4266}
4267
4268// Update the common AllocateDescriptorSetsData
4269void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004270 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004271 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05004272 auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004273 if (layout) {
4274 ds_data->layout_nodes[i] = layout;
4275 // Count total descriptors required per type
4276 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4277 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004278 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4279 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004280 }
4281 }
4282 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4283 }
4284}
4285
4286// Decrement allocated sets from the pool and insert new sets into set_map
4287void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
4288 const VkDescriptorSet *descriptor_sets,
4289 const cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
4290 auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get();
4291 // Account for sets and individual descriptors allocated from pool
4292 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
4293 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
4294 pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first);
4295 }
4296
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07004297 const auto *variable_count_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(p_alloc_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06004298 bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount;
4299
4300 // Create tracking object for each descriptor set; insert into global map and the pool's set.
4301 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
4302 uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0;
4303
Jeff Bolz41a1ced2019-10-11 11:40:49 -05004304 auto new_ds = std::make_shared<cvdescriptorset::DescriptorSet>(descriptor_sets[i], pool_state, ds_data->layout_nodes[i],
John Zulaufd2c3dae2019-12-12 11:02:17 -07004305 variable_count, this);
locke-lunargd556cc32019-09-17 01:21:23 -06004306 pool_state->sets.insert(new_ds.get());
locke-lunargd556cc32019-09-17 01:21:23 -06004307 setMap[descriptor_sets[i]] = std::move(new_ds);
4308 }
4309}
4310
locke-lunargd556cc32019-09-17 01:21:23 -06004311void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4312 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004313 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004314 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw()");
locke-lunargd556cc32019-09-17 01:21:23 -06004315}
4316
Tony-LunarG745150c2021-07-02 15:07:31 -06004317void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4318 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4319 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004320 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004321 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMultiEXT()");
Tony-LunarG745150c2021-07-02 15:07:31 -06004322}
4323
locke-lunargd556cc32019-09-17 01:21:23 -06004324void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4325 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4326 uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004327 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004328 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed()");
locke-lunargd556cc32019-09-17 01:21:23 -06004329}
4330
Tony-LunarG745150c2021-07-02 15:07:31 -06004331void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4332 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4333 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4334 const int32_t *pVertexOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004335 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004336 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMultiIndexedEXT()");
Tony-LunarG745150c2021-07-02 15:07:31 -06004337}
4338
locke-lunargd556cc32019-09-17 01:21:23 -06004339void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4340 uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004341 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004342 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004343 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect()");
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004344 if (!disabled[command_buffer_state]) {
4345 cb_state->AddChild(buffer_state);
4346 }
locke-lunargd556cc32019-09-17 01:21:23 -06004347}
4348
4349void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4350 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004351 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004352 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004353 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect()");
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004354 if (!disabled[command_buffer_state]) {
4355 cb_state->AddChild(buffer_state);
4356 }
locke-lunargd556cc32019-09-17 01:21:23 -06004357}
4358
4359void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004360 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004361 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch()");
locke-lunargd556cc32019-09-17 01:21:23 -06004362}
4363
4364void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4365 VkDeviceSize offset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004366 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004367 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect()");
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004368 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004369 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004370 cb_state->AddChild(buffer_state);
4371 }
locke-lunargd556cc32019-09-17 01:21:23 -06004372}
4373
Tony-LunarG977448c2019-12-02 14:52:02 -07004374void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4375 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
locke-lunarg540b2252020-08-03 13:23:36 -06004376 uint32_t stride, const char *function) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004377 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004378 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004379 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004380 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4381 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004382 cb_state->AddChild(buffer_state);
4383 cb_state->AddChild(count_buffer_state);
4384 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004385}
4386
locke-lunargd556cc32019-09-17 01:21:23 -06004387void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4388 VkDeviceSize offset, VkBuffer countBuffer,
4389 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4390 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004391 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
4392 "vkCmdDrawIndirectCountKHR()");
Tony-LunarG977448c2019-12-02 14:52:02 -07004393}
4394
4395void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4396 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4397 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004398 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
4399 "vkCmdDrawIndirectCount()");
Tony-LunarG977448c2019-12-02 14:52:02 -07004400}
4401
4402void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4403 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
locke-lunarg540b2252020-08-03 13:23:36 -06004404 uint32_t maxDrawCount, uint32_t stride, const char *function) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004405 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004406 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004407 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004408 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4409 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004410 cb_state->AddChild(buffer_state);
4411 cb_state->AddChild(count_buffer_state);
4412 }
locke-lunargd556cc32019-09-17 01:21:23 -06004413}
4414
4415void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4416 VkDeviceSize offset, VkBuffer countBuffer,
4417 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4418 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004419 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
4420 "vkCmdDrawIndexedIndirectCountKHR()");
Tony-LunarG977448c2019-12-02 14:52:02 -07004421}
4422
4423void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4424 VkDeviceSize offset, VkBuffer countBuffer,
4425 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4426 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004427 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
4428 "vkCmdDrawIndexedIndirectCount()");
locke-lunargd556cc32019-09-17 01:21:23 -06004429}
4430
4431void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4432 uint32_t firstTask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004433 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004434 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMeshTasksNV()");
locke-lunargd556cc32019-09-17 01:21:23 -06004435}
4436
4437void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4438 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004439 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004440 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS,
4441 "vkCmdDrawMeshTasksIndirectNV()");
locke-lunargd556cc32019-09-17 01:21:23 -06004442 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004443 if (!disabled[command_buffer_state] && buffer_state) {
4444 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004445 }
4446}
4447
4448void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4449 VkDeviceSize offset, VkBuffer countBuffer,
4450 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4451 uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004452 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004453 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS,
4454 "vkCmdDrawMeshTasksIndirectCountNV()");
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004455 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004456 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4457 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004458 if (buffer_state) {
4459 cb_state->AddChild(buffer_state);
4460 }
4461 if (count_buffer_state) {
4462 cb_state->AddChild(count_buffer_state);
4463 }
locke-lunargd556cc32019-09-17 01:21:23 -06004464 }
4465}
4466
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004467void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4468 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4469 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4470 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4471 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4472 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4473 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004474 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004475 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV, "vkCmdTraceRaysNV()");
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004476 cb_state->hasTraceRaysCmd = true;
4477}
4478
4479
4480void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4481 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4482 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4483 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4484 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4485 uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004486 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004487 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, "vkCmdTraceRaysKHR()");
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004488 cb_state->hasTraceRaysCmd = true;
4489}
4490
4491void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4492 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4493 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4494 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4495 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4496 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004497 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004498 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR,
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004499 "vkCmdTraceRaysIndirectKHR()");
4500 cb_state->hasTraceRaysCmd = true;
4501}
4502
locke-lunargd556cc32019-09-17 01:21:23 -06004503void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4504 const VkAllocationCallbacks *pAllocator,
4505 VkShaderModule *pShaderModule, VkResult result,
4506 void *csm_state_data) {
4507 if (VK_SUCCESS != result) return;
4508 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4509
Tony-LunarG8a51b7d2020-07-01 15:57:23 -06004510 spv_target_env spirv_environment = PickSpirvEnv(api_version, (device_extensions.vk_khr_spirv_1_4 != kNotEnabled));
locke-lunargd556cc32019-09-17 01:21:23 -06004511 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004512 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4513 csm_state->unique_shader_id)
4514 : std::make_shared<SHADER_MODULE_STATE>();
sfricke-samsung962cad92021-04-13 00:46:29 -07004515 new_shader_module->SetPushConstantUsedInShader();
locke-lunargd556cc32019-09-17 01:21:23 -06004516 shaderModuleMap[*pShaderModule] = std::move(new_shader_module);
4517}
4518
John Zulauf22b0fbe2019-10-15 06:26:16 -06004519void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4520 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4521 VkResult result) {
4522 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004523 auto swapchain_state = GetShared<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004524
4525 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4526
4527 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004528 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004529 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004530 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004531
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004532 auto format_features =
4533 GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format,
4534 swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004535
Jeremy Gebbenbcba6d32021-07-16 11:41:41 -06004536 auto image_state = std::make_shared<IMAGE_STATE>(device, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004537 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004538 if (!swapchain_image.fake_base_address) {
4539 auto size = image_state->fragment_encoder->TotalSize();
4540 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004541 }
4542
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004543 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004544 swapchain_image.image_state = image_state.get();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004545 imageMap[pSwapchainImages[i]] = std::move(image_state);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004546 }
4547 }
4548
4549 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004550 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4551 }
4552}
sourav parmar35e7a002020-06-09 17:58:44 -07004553
sourav parmar35e7a002020-06-09 17:58:44 -07004554void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4555 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004556 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004557 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004558 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07004559 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src);
4560 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004561 if (dst_as_state != nullptr && src_as_state != nullptr) {
4562 dst_as_state->built = true;
4563 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004564 if (!disabled[command_buffer_state]) {
4565 cb_state->AddChild(dst_as_state);
4566 cb_state->AddChild(src_as_state);
4567 }
sourav parmar35e7a002020-06-09 17:58:44 -07004568 }
4569 }
4570}
Piers Daniell39842ee2020-07-10 16:42:33 -06004571
4572void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004573 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004574 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004575}
4576
4577void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004578 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004579 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004580}
4581
4582void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4583 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004584 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004585 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004586 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004587}
4588
4589void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4590 const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004591 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004592 cb_state->RecordStateCmd(CMD_SETVIEWPORTWITHCOUNTEXT, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004593 uint32_t bits = (1u << viewportCount) - 1u;
4594 cb_state->viewportWithCountMask |= bits;
4595 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004596 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004597 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004598
4599 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4600 for (size_t i = 0; i < viewportCount; ++i) {
4601 cb_state->dynamicViewports[i] = pViewports[i];
4602 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004603}
4604
4605void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4606 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004607 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004608 cb_state->RecordStateCmd(CMD_SETSCISSORWITHCOUNTEXT, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004609 uint32_t bits = (1u << scissorCount) - 1u;
4610 cb_state->scissorWithCountMask |= bits;
4611 cb_state->trashedScissorMask &= ~bits;
4612 cb_state->scissorWithCountCount = scissorCount;
4613 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004614}
4615
4616void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4617 uint32_t bindingCount, const VkBuffer *pBuffers,
4618 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4619 const VkDeviceSize *pStrides) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004620 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004621 cb_state->RecordStateCmd(CMD_BINDVERTEXBUFFERS2EXT, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004622
4623 uint32_t end = firstBinding + bindingCount;
4624 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4625 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4626 }
4627
4628 for (uint32_t i = 0; i < bindingCount; ++i) {
4629 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07004630 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004631 vertex_buffer_binding.offset = pOffsets[i];
4632 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4633 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4634 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004635 if (!disabled[command_buffer_state] && pBuffers[i]) {
4636 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Piers Daniell39842ee2020-07-10 16:42:33 -06004637 }
4638 }
4639}
4640
4641void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004642 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004643 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004644}
4645
4646void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004647 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004648 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004649}
4650
4651void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004652 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004653 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004654}
4655
4656void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4657 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004658 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004659 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004660}
4661void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004662 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004663 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004664}
4665
4666void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4667 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4668 VkCompareOp compareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004669 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004670 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004671}
locke-lunarg4189aa22020-10-21 00:23:48 -06004672
4673void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4674 uint32_t discardRectangleCount,
4675 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004676 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004677 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004678}
4679
4680void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4681 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004682 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004683 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004684}
4685
4686void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4687 VkCoarseSampleOrderTypeNV sampleOrderType,
4688 uint32_t customSampleOrderCount,
4689 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004690 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004691 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004692}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004693
4694void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004695 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004696 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004697}
4698
4699void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004700 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004701 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004702}
4703
4704void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4705 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004706 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004707 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004708}
4709
4710void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004711 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004712 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004713}
4714
4715void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4716 VkBool32 primitiveRestartEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004717 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004718 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004719}
Piers Daniell924cd832021-05-18 13:48:47 -06004720
4721void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4722 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4723 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4724 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004725 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004726 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4727
4728 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4729 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4730 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004731 if (pipeline_state->create_info.graphics.pDynamicState) {
4732 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4733 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004734 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4735 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4736 break;
4737 }
4738 }
4739 }
4740 }
4741 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004742}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004743
4744void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
4745 BUFFER_STATE *buffer_state = GetBufferState(pInfo->buffer);
4746 if (buffer_state) {
4747 // address is used for GPU-AV and ray tracing buffer validation
4748 buffer_state->deviceAddress = address;
4749 buffer_address_map_.emplace(address, buffer_state);
4750 }
4751}
4752
4753void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4754 VkDeviceAddress address) {
4755 RecordGetBufferDeviceAddress(pInfo, address);
4756}
4757
4758void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4759 VkDeviceAddress address) {
4760 RecordGetBufferDeviceAddress(pInfo, address);
4761}
4762
4763void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4764 VkDeviceAddress address) {
4765 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004766}
4767
4768std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4769 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004770 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004771}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004772
4773std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4774 const VkCommandBufferAllocateInfo *create_info,
4775 std::shared_ptr<COMMAND_POOL_STATE> &pool) {
4776 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4777}