blob: b48e7a39ec00a66dc8cb20c03e141e4dd02572e7 [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 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
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
sjfrickee9b39372022-05-22 13:02:17 +0900137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200138
139 // Find the image modifier
140 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
141
142 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
143 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
144 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
145
146 // Second query to have all the modifiers filled
147 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
148
149 // Look for the image modifier in the list
150 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
151 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
152 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
153 break;
154 }
155 }
156 } else {
157 format_features =
158 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
159 }
160 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
sjfrickee9b39372022-05-22 13:02:17 +0900161 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600162 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200163
sjfrickee9b39372022-05-22 13:02:17 +0900164 VkFormatProperties2 format_properties_2 = LvlInitStruct<VkFormatProperties2>();
165 VkDrmFormatModifierPropertiesListEXT drm_properties_list = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600166 format_properties_2.pNext = (void *)&drm_properties_list;
167 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
168 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
169 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
170 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
171 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200172
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600173 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
174 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
175 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
176 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200177 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200178 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600179 } else {
180 VkFormatProperties format_properties;
181 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
182 format_features =
183 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200184 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600185 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200186}
187
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700188std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
189 VkFormatFeatureFlags2KHR features) {
Aitor Camacho3294edd2022-05-16 22:34:19 +0200190 std::shared_ptr<IMAGE_STATE> state;
191
192 if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
193 if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) {
194 state = std::make_shared<IMAGE_STATE_SPARSE<true>>(this, img, pCreateInfo, features);
195 } else {
196 state = std::make_shared<IMAGE_STATE_SPARSE<false>>(this, img, pCreateInfo, features);
197 }
198 } else if (pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
199 uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
200 switch (plane_count) {
201 case 3:
202 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<3>>(this, img, pCreateInfo, features);
203 break;
204 case 2:
205 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<2>>(this, img, pCreateInfo, features);
206 break;
207 case 1:
208 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<1>>(this, img, pCreateInfo, features);
209 break;
210 default:
Shahbaz Youssefi87f53002022-06-07 10:14:01 -0400211 // Not supported
212 assert(false);
Aitor Camacho3294edd2022-05-16 22:34:19 +0200213 }
214 } else {
215 state = std::make_shared<IMAGE_STATE_LINEAR>(this, img, pCreateInfo, features);
216 }
217
218 return state;
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700219}
220
221std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
222 VkSwapchainKHR swapchain, uint32_t swapchain_index,
223 VkFormatFeatureFlags2KHR features) {
Aitor Camacho3294edd2022-05-16 22:34:19 +0200224 return std::make_shared<IMAGE_STATE_NO_BINDING>(this, img, pCreateInfo, swapchain, swapchain_index, features);
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700225}
226
locke-lunargd556cc32019-09-17 01:21:23 -0600227void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
228 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
229 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200230 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700231 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600232 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600233 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600234 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200235 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
236 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
237 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600238 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700239 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600240}
241
242void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600243 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600244}
245
246void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
247 VkImageLayout imageLayout, const VkClearColorValue *pColor,
248 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600252 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600253 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600254 }
255}
256
257void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
258 VkImageLayout imageLayout,
259 const VkClearDepthStencilValue *pDepthStencil,
260 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600261 if (disabled[command_buffer_state]) return;
262
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700263 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600264 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600265 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600266 }
267}
268
269void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
270 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
271 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600272 if (disabled[command_buffer_state]) return;
273
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700274 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600275 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600276}
277
Jeff Leger178b1e52020-10-05 12:22:23 -0400278void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
279 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600280 if (disabled[command_buffer_state]) return;
281
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700282 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600283 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
284 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400285}
286
Tony-LunarGb61514a2021-11-02 12:36:51 -0600287void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
288 if (disabled[command_buffer_state]) return;
289
290 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
291 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
292 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
293}
294
locke-lunargd556cc32019-09-17 01:21:23 -0600295void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
296 VkImageLayout srcImageLayout, VkImage dstImage,
297 VkImageLayout dstImageLayout, uint32_t regionCount,
298 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600299 if (disabled[command_buffer_state]) return;
300
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700301 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600302 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600303}
304
Jeff Leger178b1e52020-10-05 12:22:23 -0400305void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
306 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600307 if (disabled[command_buffer_state]) return;
308
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700309 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600310 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
311 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400312}
313
Tony-LunarG562fc102021-11-12 13:58:35 -0700314void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
315 const VkResolveImageInfo2 *pResolveImageInfo) {
316 if (disabled[command_buffer_state]) return;
317
318 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
319 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
320 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
321}
322
locke-lunargd556cc32019-09-17 01:21:23 -0600323void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
324 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
325 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600326 if (disabled[command_buffer_state]) return;
327
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700328 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600329 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600330}
331
Jeff Leger178b1e52020-10-05 12:22:23 -0400332void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
333 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600334 if (disabled[command_buffer_state]) return;
335
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700336 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600337 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
338 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400339}
340
Tony-LunarG542ae912021-11-04 16:06:44 -0600341void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
342 if (disabled[command_buffer_state]) return;
343
344 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
345 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
346 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
347}
348
locke-lunargd556cc32019-09-17 01:21:23 -0600349void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
350 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
351 VkResult result) {
352 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600353
Aitor Camacho3294edd2022-05-16 22:34:19 +0200354 std::shared_ptr<BUFFER_STATE> buffer_state;
355 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) {
356 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) {
357 buffer_state = std::make_shared<BUFFER_STATE_SPARSE<true>>(this, *pBuffer, pCreateInfo);
358 } else {
359 buffer_state = std::make_shared<BUFFER_STATE_SPARSE<false>>(this, *pBuffer, pCreateInfo);
360 }
361 } else {
362 buffer_state = std::make_shared<BUFFER_STATE_LINEAR>(this, *pBuffer, pCreateInfo);
363 }
locke-lunargd556cc32019-09-17 01:21:23 -0600364
James Rumble2f6e7bb2021-07-13 15:21:20 +0100365 if (pCreateInfo) {
366 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700367 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700368 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100369 // address is used for GPU-AV and ray tracing buffer validation
370 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700371 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100372 }
373 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600374 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600375}
376
377void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
378 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
379 VkResult result) {
380 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600381
Jeremy Gebben9f537102021-10-05 16:37:12 -0600382 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600383
ziga-lunarg7b29e662022-08-29 02:32:48 +0200384 VkFormatFeatureFlags2KHR buffer_features;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200385 if (has_format_feature2) {
386 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
387 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
388 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
389 buffer_features = fmt_props_3.bufferFeatures;
390 } else {
391 VkFormatProperties format_properties;
392 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
393 buffer_features = format_properties.bufferFeatures;
394 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600395
ziga-lunarg7b29e662022-08-29 02:32:48 +0200396 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600397}
398
399void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
400 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
401 VkResult result) {
402 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600403 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700404
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200405 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600406 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700407 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600408 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700409 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200410 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
411 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
412 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700413 }
414
locke-lunarg9939d4b2020-10-26 20:11:08 -0600415 // 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 -0600416 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600417 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700418 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600419 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700420 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600421 image_format_info.type = image_state->createInfo.imageType;
422 image_format_info.format = image_state->createInfo.format;
423 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600424 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
425 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600426 image_format_info.flags = image_state->createInfo.flags;
427
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600428 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600429
430 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
431 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600432
Jeremy Gebben082a9832021-10-28 13:40:11 -0600433 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600434}
435
436void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
437 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600438 if (disabled[command_buffer_state]) return;
439
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700440 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600441 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600442}
443
Jeff Leger178b1e52020-10-05 12:22:23 -0400444void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600445 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600446 if (disabled[command_buffer_state]) return;
447
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700448 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600449 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
450 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400451}
452
Tony-LunarGef035472021-11-02 10:23:33 -0600453void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
454 if (disabled[command_buffer_state]) return;
455
456 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
457 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
458 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
459}
460
locke-lunargd556cc32019-09-17 01:21:23 -0600461void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
462 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600463 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600464}
465
466void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700467 auto buffer_state = Get<BUFFER_STATE>(buffer);
468 if (buffer_state) {
469 WriteLockGuard guard(buffer_address_lock_);
470 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
471 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600472 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600473}
474
475void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
476 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600477 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600478}
479
480void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
481 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600482 if (disabled[command_buffer_state]) return;
483
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700484 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600485 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600486}
487
488void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
489 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
490 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600491 if (disabled[command_buffer_state]) return;
492
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700493 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600494
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600495 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600496}
497
Jeff Leger178b1e52020-10-05 12:22:23 -0400498void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
499 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600500 if (disabled[command_buffer_state]) return;
501
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700502 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600503 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
504 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400505}
506
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700507void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
508 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
509 if (disabled[command_buffer_state]) return;
510
511 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
512 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
513 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
514}
515
locke-lunargd556cc32019-09-17 01:21:23 -0600516void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
517 VkImageLayout dstImageLayout, uint32_t regionCount,
518 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600519 if (disabled[command_buffer_state]) return;
520
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700521 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600522 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600523}
524
Jeff Leger178b1e52020-10-05 12:22:23 -0400525void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
526 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600527 if (disabled[command_buffer_state]) return;
528
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700529 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600530 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
531 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400532}
533
Tony Barbour845d29b2021-11-09 11:43:14 -0700534void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
535 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
536 if (disabled[command_buffer_state]) return;
537
538 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
539 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
540 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
541}
542
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700543// Gets union of all features defined by Potential Format Features
544// except, does not handle the external format case for AHB as that only can be used for sampled images
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200545VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
546 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700547
548 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200549 if (has_format_feature2) {
550 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200551 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
552 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200553 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100554
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200555 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100556
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200557 format_features |= fmt_props_3.linearTilingFeatures;
558 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100559
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200560 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
561 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
562 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
563 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
564 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100565
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200566 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
567 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
568 }
569 }
570 } else {
571 VkFormatProperties format_properties;
572 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
573 format_features |= format_properties.linearTilingFeatures;
574 format_features |= format_properties.optimalTilingFeatures;
575
576 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
577 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
578 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
579
580 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
581
582 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
583 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
584 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
585 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
586
587 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
588 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
589 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700590 }
591 }
592 }
593
594 return format_features;
595}
596
locke-lunargd556cc32019-09-17 01:21:23 -0600597void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
598 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
599 VkResult result) {
600 if (VK_SUCCESS != result) return;
601
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600602 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600603 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
604 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600605 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600606
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600607 device_state->instance_state = this;
608 // Save local link to this device's physical device state
609 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
610 // finish setup in the object representing the device
611 device_state->CreateDevice(pCreateInfo);
612}
613
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -0300614std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags, const VkQueueFamilyProperties &queueFamilyProperties) {
615 return std::make_shared<QUEUE_STATE>(q, index, flags, queueFamilyProperties);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -0600616}
617
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600618void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600619 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
620 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700621 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600622 if (features2) {
623 enabled_features_found = &(features2->features);
624 }
625 }
626
locke-lunargd556cc32019-09-17 01:21:23 -0600627 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600628 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600629 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600630 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600631 }
632
Tony-LunarG273f32f2021-09-28 08:56:30 -0600633 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
634 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600635 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600636 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600637 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600638 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
639 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600640 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600641 }
642
643 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
644 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600645 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
646 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600647 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
648 }
649
650 const auto *pipeline_creation_cache_control_features =
651 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
652 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600653 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600654 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
655 }
656
657 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
658 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600659 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600660 }
661
662 const auto *demote_to_helper_invocation_features =
663 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
664 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600665 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600666 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
667 }
668
669 const auto *terminate_invocation_features =
670 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
671 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600672 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600673 }
674
675 const auto *subgroup_size_control_features =
676 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
677 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600678 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
679 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600680 }
681
682 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
683 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600684 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600685 }
686
687 const auto *texture_compression_astchdr_features =
688 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
689 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600690 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600691 }
692
693 const auto *initialize_workgroup_memory_features =
694 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
695 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600696 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600697 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
698 }
699
700 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
701 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600702 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600703 }
704
705 const auto *shader_integer_dot_product_features =
706 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
707 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600708 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600709 }
710
711 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
712 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600713 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600714 }
715 }
716
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700717 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700718 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600719 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700720 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700721 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.drawIndirectCount = VK_FALSE;
723 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
724 enabled_features.core12.descriptorIndexing = VK_FALSE;
725 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
726 enabled_features.core12.shaderOutputLayer = VK_FALSE;
727 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
728 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700729
730 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700731
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700732 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700733 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
735 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700736 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600737 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700738 }
739
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700740 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700741 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
743 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700744 }
745
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700746 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700747 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600748 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700749 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600750 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700751 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600752 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700753 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700755 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600756 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700757 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600758 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700759 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700761 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600762 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700763 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600764 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700765 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600768 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700769 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600770 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700771 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600772 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700773 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600774 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700775 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600776 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700777 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600778 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700779 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600780 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700781 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600782 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
783 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700784 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600785 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700786 }
787
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700788 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700789 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600790 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 }
792
793 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700794 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700795 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600796 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700797 }
798
799 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700800 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700801 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600802 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700803 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700804 }
805
806 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700807 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700808 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600809 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700810 }
811
812 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700813 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700814 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600815 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700816 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700817 }
818
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700819 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700820 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600821 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700822 }
823
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700824 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700825 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600826 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700827 }
828
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700829 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700830 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600831 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
832 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
833 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700834 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800835
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700836 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800837 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600838 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
839 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800840 }
841
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700842 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800843 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600844 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
845 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
846 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800847 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
848 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 }
850
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700851 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700852 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600853 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700854 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700855 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700856
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700857 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700858 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600859 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
860 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700861 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600862 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
863 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700864 }
865
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700866 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700867 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600868 enabled_features.core11.multiview = multiview_features->multiview;
869 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
870 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700871 }
872
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700873 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700874 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600875 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
876 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700877 }
878
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700879 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700880 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600881 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700882 }
883
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700884 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700885 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600886 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700887 }
888
889 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700890 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700891 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600892 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700893 }
894 }
895
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700896 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600897 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600898 physical_device_count = device_group_ci->physicalDeviceCount;
899 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600900 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600901 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600902 }
locke-lunargd556cc32019-09-17 01:21:23 -0600903
sfricke-samsung828e59d2021-08-22 23:20:49 -0700904 // Features from other extensions passesd in create info
905 {
906 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
907 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600908 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700909 }
locke-lunargd556cc32019-09-17 01:21:23 -0600910
sfricke-samsung828e59d2021-08-22 23:20:49 -0700911 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
912 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600913 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700914 }
locke-lunargd556cc32019-09-17 01:21:23 -0600915
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
917 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600918 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700919 }
locke-lunargd556cc32019-09-17 01:21:23 -0600920
sfricke-samsung828e59d2021-08-22 23:20:49 -0700921 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
922 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600923 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 }
locke-lunargd556cc32019-09-17 01:21:23 -0600925
sfricke-samsung828e59d2021-08-22 23:20:49 -0700926 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
927 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600928 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700929 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700930
sfricke-samsung828e59d2021-08-22 23:20:49 -0700931 const auto *buffer_device_address_ext_features =
932 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
933 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600934 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700935 }
locke-lunargd556cc32019-09-17 01:21:23 -0600936
sfricke-samsung828e59d2021-08-22 23:20:49 -0700937 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
938 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600939 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *compute_shader_derivatives_features =
943 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
944 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600945 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 }
locke-lunargd556cc32019-09-17 01:21:23 -0600947
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 const auto *fragment_shader_barycentric_features =
949 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
950 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600951 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700952 }
locke-lunargd556cc32019-09-17 01:21:23 -0600953
sfricke-samsung828e59d2021-08-22 23:20:49 -0700954 const auto *shader_image_footprint_features =
955 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
956 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600957 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700958 }
locke-lunargd556cc32019-09-17 01:21:23 -0600959
sfricke-samsung828e59d2021-08-22 23:20:49 -0700960 const auto *fragment_shader_interlock_features =
961 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
962 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600963 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700964 }
locke-lunargd556cc32019-09-17 01:21:23 -0600965
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 const auto *texel_buffer_alignment_features =
967 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
968 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600969 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700970 }
locke-lunargd556cc32019-09-17 01:21:23 -0600971
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 const auto *pipeline_exe_props_features =
973 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
974 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600975 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700976 }
locke-lunargd556cc32019-09-17 01:21:23 -0600977
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 const auto *dedicated_allocation_image_aliasing_features =
979 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
980 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600981 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700982 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500983
sfricke-samsung828e59d2021-08-22 23:20:49 -0700984 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
985 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600986 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700987 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100988
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
990 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600991 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700992 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000993
sfricke-samsung828e59d2021-08-22 23:20:49 -0700994 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
995 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600996 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700997 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800998
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
1000 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001001 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001002 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001003
sfricke-samsung828e59d2021-08-22 23:20:49 -07001004 const auto *ray_tracing_pipeline_features =
1005 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
1006 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001007 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001009
sfricke-samsung828e59d2021-08-22 23:20:49 -07001010 const auto *ray_tracing_acceleration_structure_features =
1011 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
1012 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001013 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001014 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001015
sfricke-samsung828e59d2021-08-22 23:20:49 -07001016 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
1017 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001018 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001019 }
Jeff Bolz165818a2020-05-08 11:19:03 -05001020
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 const auto *fragment_density_map_features =
1022 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1023 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001024 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001025 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001026
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 const auto *fragment_density_map_features2 =
1028 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1029 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001030 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001031 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001032
Agarwal, Arpit78509112022-02-17 15:29:05 -07001033 const auto *fragment_density_map_offset_features =
1034 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1035 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001036 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001037 }
1038
sfricke-samsung828e59d2021-08-22 23:20:49 -07001039 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1040 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001041 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001042 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001043
sfricke-samsung828e59d2021-08-22 23:20:49 -07001044 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1045 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001046 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001047 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001048
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 const auto *fragment_shading_rate_features =
1050 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1051 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001052 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001053 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001054
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001055 const auto *fragment_shading_rate_enums_features =
1056 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1057 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001058 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001059 }
1060
sfricke-samsung828e59d2021-08-22 23:20:49 -07001061 const auto *extended_dynamic_state_features =
1062 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1063 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001064 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001065 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001066
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 const auto *extended_dynamic_state2_features =
1068 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1069 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001070 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001071 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001072
sfricke-samsung828e59d2021-08-22 23:20:49 -07001073 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1074 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001075 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001076 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001077
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1079 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001080 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001081 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001082
sfricke-samsung828e59d2021-08-22 23:20:49 -07001083 const auto *shader_integer_functions2_features =
1084 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1085 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001086 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001087 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001088
sfricke-samsung828e59d2021-08-22 23:20:49 -07001089 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1090 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001091 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001092 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001093
sfricke-samsung828e59d2021-08-22 23:20:49 -07001094 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1095 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001096 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001097 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001098
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 const auto *shader_image_atomic_int64_features =
1100 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1101 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001102 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001103 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001104
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1106 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001107 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001108 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001109
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 const auto *conditional_rendering_features =
1111 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1112 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001113 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001114 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001115
sfricke-samsung828e59d2021-08-22 23:20:49 -07001116 const auto *workgroup_memory_explicit_layout_features =
1117 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1118 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001119 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001120 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001121
sfricke-samsung828e59d2021-08-22 23:20:49 -07001122 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1123 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001124 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001125 }
Locke Linf3873542021-04-26 11:25:10 -06001126
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 const auto *vertex_input_dynamic_state_features =
1128 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1129 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001130 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001131 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001132
sfricke-samsung828e59d2021-08-22 23:20:49 -07001133 const auto *inherited_viewport_scissor_features =
1134 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1135 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001136 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001137 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001138
sfricke-samsung828e59d2021-08-22 23:20:49 -07001139 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1140 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001141 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001142 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001143
sfricke-samsung828e59d2021-08-22 23:20:49 -07001144 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1145 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001146 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001147 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001148
sfricke-samsung828e59d2021-08-22 23:20:49 -07001149 const auto *shader_atomic_float2_features =
1150 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1151 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001152 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001153 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001154
sfricke-samsung828e59d2021-08-22 23:20:49 -07001155 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1156 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001157 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001158 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001159
sfricke-samsung828e59d2021-08-22 23:20:49 -07001160 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1161 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001162 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001163 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001164
1165 const auto *ray_tracing_motion_blur_features =
1166 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1167 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001168 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001169 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001170
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001171 const auto *primitive_topology_list_restart_features =
1172 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1173 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001174 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001175 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001176
ziga-lunarge1988962021-09-16 13:32:34 +02001177 const auto *zero_initialize_work_group_memory_features =
1178 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1179 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001180 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001181 }
1182
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001183 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1184 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001185 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001186 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001187
Tony-LunarG69604c42021-11-22 16:00:12 -07001188 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1189 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001190 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001191 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001192
1193 const auto *primitives_generated_query_features =
1194 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1195 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001196 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001197 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001198
1199 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1200 if (image_2d_view_of_3d_features) {
1201 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1202 }
Nathaniel Cesario553ab032022-04-14 10:56:22 -06001203
1204 const auto graphics_pipeline_library_features =
1205 LvlFindInChain<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(pCreateInfo->pNext);
1206 if (graphics_pipeline_library_features) {
1207 enabled_features.graphics_pipeline_library_features = *graphics_pipeline_library_features;
1208 }
ziga-lunarge25f5f02022-04-16 15:07:35 +02001209
1210 const auto shader_subgroup_uniform_control_flow_features =
1211 LvlFindInChain<VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR>(pCreateInfo->pNext);
1212 if (shader_subgroup_uniform_control_flow_features) {
1213 enabled_features.shader_subgroup_uniform_control_flow_features = *shader_subgroup_uniform_control_flow_features;
1214 }
Mike Schuchardt840f1252022-05-11 11:31:25 -07001215
sjfrickee9b39372022-05-22 13:02:17 +09001216 const auto ray_tracing_maintenance1_features =
Mike Schuchardt840f1252022-05-11 11:31:25 -07001217 LvlFindInChain<VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR>(pCreateInfo->pNext);
1218 if (ray_tracing_maintenance1_features) {
1219 enabled_features.ray_tracing_maintenance1_features= *ray_tracing_maintenance1_features;
1220 }
sjfricke52defd42022-08-08 16:37:46 +09001221
Tony-LunarG206b1bb2022-06-13 12:20:05 -06001222 const auto non_seamless_cube_map_features =
1223 LvlFindInChain<VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT>(pCreateInfo->pNext);
1224 if (non_seamless_cube_map_features) {
1225 enabled_features.non_seamless_cube_map_features = *non_seamless_cube_map_features;
1226 }
Tony-LunarG7384f7e2022-07-05 14:20:42 -06001227
1228 const auto multisampled_render_to_single_sampled_features =
1229 LvlFindInChain<VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT>(pCreateInfo->pNext);
1230 if (multisampled_render_to_single_sampled_features) {
1231 enabled_features.multisampled_render_to_single_sampled_features = *multisampled_render_to_single_sampled_features;
1232 }
Tony-LunarG1672d002022-08-03 14:35:34 -06001233
1234 const auto shader_module_identifier_features =
1235 LvlFindInChain<VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT>(pCreateInfo->pNext);
1236 if (shader_module_identifier_features) {
1237 enabled_features.shader_module_identifier_features = *shader_module_identifier_features;
1238 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001239 }
1240
locke-lunargd556cc32019-09-17 01:21:23 -06001241 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001242 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1243 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001244
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001245 {
1246 uint32_t n_props = 0;
1247 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001248 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001249 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001250 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001251
1252 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001253 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001254 }
1255
1256 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1257 // a path to grab that information from the physical device. This
1258 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1259 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001260 has_format_feature2 =
1261 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1262 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001263 }
1264
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001265 const auto &dev_ext = device_extensions;
1266 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001267
Tony-LunarG273f32f2021-09-28 08:56:30 -06001268 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1269 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001270 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1271 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001272 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001273 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001274 } else {
1275 // VkPhysicalDeviceVulkan11Properties
1276 //
1277 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1278
1279 if (dev_ext.vk_khr_multiview) {
1280 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001281 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1282 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1283 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001284 }
1285
1286 if (dev_ext.vk_khr_maintenance3) {
1287 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001288 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1289 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1290 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001291 }
1292
1293 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001294 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001295 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1296 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1297 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001298 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001299
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001300 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1301 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1302 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1303 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001304
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001305 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306 }
1307
1308 // VkPhysicalDeviceVulkan12Properties
1309 //
1310 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1311
1312 if (dev_ext.vk_ext_descriptor_indexing) {
1313 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001314 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1315 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001316 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001317 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001318 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001319 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001320 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001321 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001322 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001323 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001324 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001325 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001326 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001327 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1328 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1329 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001330 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001331 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001332 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001333 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001334 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001335 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001336 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001337 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001338 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001339 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001340 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001341 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001342 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001343 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001344 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001345 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001346 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001347 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001348 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001349 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001350 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001351 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001352 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001353 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001354 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001355 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001356 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001357 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001358 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1359 }
1360
1361 if (dev_ext.vk_khr_depth_stencil_resolve) {
1362 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001363 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1364 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1365 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1366 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1367 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001368 }
1369
1370 if (dev_ext.vk_khr_timeline_semaphore) {
1371 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001372 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1373 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001374 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1375 }
1376
1377 if (dev_ext.vk_ext_sampler_filter_minmax) {
1378 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001379 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1380 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001381 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001382 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001383 }
1384
1385 if (dev_ext.vk_khr_shader_float_controls) {
1386 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001387 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1388 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1389 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1390 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001391 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001392 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001393 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001394 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001395 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001396 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1397 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1398 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1399 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1400 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1401 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1402 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1403 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1404 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1405 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1406 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1407 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001408 }
locke-lunargd556cc32019-09-17 01:21:23 -06001409 }
1410
sfricke-samsung828e59d2021-08-22 23:20:49 -07001411 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001412 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1413 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1414 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1415 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1416 &phys_dev_props->inline_uniform_block_props);
1417 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1418 &phys_dev_props->vtx_attrib_divisor_props);
1419 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1420 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1421 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1422 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1423 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1424 &phys_dev_props->texel_buffer_alignment_props);
1425 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1426 &phys_dev_props->fragment_density_map_props);
1427 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1428 &phys_dev_props->fragment_density_map2_props);
1429 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001430 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001431 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1432 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1433 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1434 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1435 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1436 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1437 &phys_dev_props->fragment_shading_rate_props);
1438 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1439 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1440 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1441 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1442 &phys_dev_props->blend_operation_advanced_props);
1443 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1444 &phys_dev_props->conservative_rasterization_props);
1445 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1446 &phys_dev_props->subgroup_size_control_props);
ziga-lunarge25f5f02022-04-16 15:07:35 +02001447 if (api_version >= VK_API_VERSION_1_1) {
1448 GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_properties);
1449 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001450
sfricke-samsung45996a42021-09-16 13:45:27 -07001451 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001452 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001453 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1454 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001455 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1456 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001457
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001458 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001459 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1460 NULL);
1461 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001462
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001463 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1464 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001465 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001466
locke-lunargd556cc32019-09-17 01:21:23 -06001467 // Store queue family data
1468 if (pCreateInfo->pQueueCreateInfos != nullptr) {
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001469 uint32_t num_queue_families = 0;
1470 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
1471 std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
1472 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
1473
locke-lunargd556cc32019-09-17 01:21:23 -06001474 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001475 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001476 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1477 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001478 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001479 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001480 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001481 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1482 VkQueue queue = VK_NULL_HANDLE;
1483 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1484 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1485 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1486 get_info.flags = queue_info.flags;
1487 get_info.queueFamilyIndex = queue_info.queue_family_index;
1488 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001489 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001490 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001491 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001492 }
1493 assert(queue != VK_NULL_HANDLE);
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001494 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags,
1495 queue_family_properties_list[queue_info.queue_family_index]));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001496 }
locke-lunargd556cc32019-09-17 01:21:23 -06001497 }
1498 }
1499}
1500
1501void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1502 if (!device) return;
1503
Jeremy Gebbend177d922021-10-28 13:42:10 -06001504 command_pool_map_.clear();
1505 assert(command_buffer_map_.empty());
1506 pipeline_map_.clear();
1507 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001508
1509 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001510 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001511 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001512 assert(descriptor_set_map_.empty());
1513 desc_template_map_.clear();
1514 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001515 // Because swapchains are associated with Surfaces, which are at instance level,
1516 // they need to be explicitly destroyed here to avoid continued references to
1517 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001518 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001519 entry.second->Destroy();
1520 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001521 swapchain_map_.clear();
1522 image_view_map_.clear();
1523 image_map_.clear();
1524 buffer_view_map_.clear();
1525 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001526 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001527 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001528}
1529
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001530void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1531 VkFence fence, VkResult result) {
1532 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001533 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001534
Jeremy Gebben57642982021-09-14 14:14:55 -06001535 uint64_t early_retire_seq = 0;
1536
1537 if (submitCount == 0) {
1538 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001539 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001540 early_retire_seq = queue_state->Submit(std::move(submission));
1541 }
locke-lunargd556cc32019-09-17 01:21:23 -06001542
1543 // Now process each individual submit
1544 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001545 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001546 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001547 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001548 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001549 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001550 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1551 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1552 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1553 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001554 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001555 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001556
locke-lunargd556cc32019-09-17 01:21:23 -06001557 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001558 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001559 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1560 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1561 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1562 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001563 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001564 }
1565
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001566 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001567 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001568
locke-lunargd556cc32019-09-17 01:21:23 -06001569 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001570 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1571 if (cb_state) {
1572 submission.AddCommandBuffer(std::move(cb_state));
1573 }
locke-lunargd556cc32019-09-17 01:21:23 -06001574 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001575 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001576 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001577 }
1578 auto submit_seq = queue_state->Submit(std::move(submission));
1579 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001580 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001581
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001582 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001583 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001584 }
1585}
1586
Tony-LunarG26fe2842021-11-16 14:07:59 -07001587void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1588 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001589 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001590 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001591 uint64_t early_retire_seq = 0;
1592 if (submitCount == 0) {
1593 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001594 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001595 early_retire_seq = queue_state->Submit(std::move(submission));
1596 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001597
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001598 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1599 CB_SUBMISSION submission;
1600 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001601 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1602 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001603 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001604 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001605 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1606 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001607 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001608 }
1609 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1610 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1611
1612 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001613 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001614 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001615 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001616 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001617 }
1618 auto submit_seq = queue_state->Submit(std::move(submission));
1619 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001620 }
locke-lunargd556cc32019-09-17 01:21:23 -06001621 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001622 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001623 }
1624}
1625
Tony-LunarG26fe2842021-11-16 14:07:59 -07001626void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1627 VkFence fence, VkResult result) {
1628 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1629}
1630
1631void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1632 VkFence fence, VkResult result) {
1633 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1634}
1635
locke-lunargd556cc32019-09-17 01:21:23 -06001636void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1637 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1638 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001639 if (VK_SUCCESS != result) {
1640 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001641 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001642 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1643 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1644 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1645
1646 layer_data::optional<DedicatedBinding> dedicated_binding;
1647
1648 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1649 if (dedicated) {
1650 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001651 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001652 assert(buffer_state);
1653 if (!buffer_state) {
1654 return;
1655 }
1656 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1657 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001658 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001659 assert(image_state);
1660 if (!image_state) {
1661 return;
1662 }
1663 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1664 }
1665 }
Rodrigo Locatti37ddb022022-03-15 17:27:42 -03001666 Add(CreateDeviceMemoryState(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap, std::move(dedicated_binding),
1667 physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001668 return;
1669}
1670
1671void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001672 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001673 if (mem_info) {
1674 fake_memory.Free(mem_info->fake_base_address);
1675 }
1676 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001677}
1678
1679void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1680 VkFence fence, VkResult result) {
1681 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001682 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001683
Jeremy Gebben57642982021-09-14 14:14:55 -06001684 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001685
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001686 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1687 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001688 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001689 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1690 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1691 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001692 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001693 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001694 if (buffer_state) {
1695 buffer_state->BindMemory(buffer_state.get(), mem_state, sparse_binding.memoryOffset,
1696 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001697 }
locke-lunargd556cc32019-09-17 01:21:23 -06001698 }
1699 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001700 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1701 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1702 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001703 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001704 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001705 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001706 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1707 // See: VUID-vkGetImageSubresourceLayout-image-01895
1708 if (!image_state->fragment_encoder) {
1709 image_state->fragment_encoder =
1710 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1711 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001712 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset,
1713 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001714 }
locke-lunargd556cc32019-09-17 01:21:23 -06001715 }
1716 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001717 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1718 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1719 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001720 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1721 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Aitor Camacho3294edd2022-05-16 22:34:19 +02001722 VkDeviceSize offset = sparse_binding.offset.z * sparse_binding.offset.y * sparse_binding.offset.x * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001723 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001724 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001725 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001726 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1727 // See: VUID-vkGetImageSubresourceLayout-image-01895
1728 if (!image_state->fragment_encoder) {
1729 image_state->fragment_encoder =
1730 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1731 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001732 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset, offset, size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001733 }
locke-lunargd556cc32019-09-17 01:21:23 -06001734 }
1735 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001736 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001737 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001738 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001739 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001740 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001741 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001742 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001743 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001744 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001745 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001746 auto submit_seq = queue_state->Submit(std::move(submission));
1747 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001748 }
1749
1750 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001751 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001752 }
1753}
1754
1755void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1756 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1757 VkResult result) {
1758 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06001759 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext), pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001760}
1761
Mike Schuchardt2df08912020-12-15 16:28:09 -08001762void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1763 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001764 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1765 if (semaphore_state) {
1766 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001767 }
1768}
1769
Mike Schuchardt2df08912020-12-15 16:28:09 -08001770void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001771 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001772 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001773 if (semaphore_state) {
1774 semaphore_state->RetireTimeline(pSignalInfo->value);
1775 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001776}
1777
locke-lunargd556cc32019-09-17 01:21:23 -06001778void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001779 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001780 if (mem_info) {
1781 mem_info->mapped_range.offset = offset;
1782 mem_info->mapped_range.size = size;
1783 mem_info->p_driver_data = *ppData;
1784 }
1785}
1786
locke-lunargd556cc32019-09-17 01:21:23 -06001787void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1788 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1789 if (VK_SUCCESS != result) return;
1790
1791 // When we know that all fences are complete we can clean/remove their CBs
1792 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1793 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001794 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001795 if (fence_state) {
1796 fence_state->Retire();
1797 }
locke-lunargd556cc32019-09-17 01:21:23 -06001798 }
1799 }
1800 // NOTE : Alternate case not handled here is when some fences have completed. In
1801 // this case for app to guarantee which fences completed it will have to call
1802 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1803}
1804
John Zulauff89de662020-04-13 18:57:34 -06001805void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1806 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001807 if (VK_SUCCESS != result) return;
1808
Jeremy Gebben15332642021-12-15 19:33:15 -07001809 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1810 // the application calls vkGetSemaphoreCounterValue() on each of them.
1811 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1812 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1813 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1814 if (semaphore_state) {
1815 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1816 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001817 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001818 }
1819}
1820
John Zulauff89de662020-04-13 18:57:34 -06001821void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1822 VkResult result) {
1823 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1824}
1825
1826void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1827 uint64_t timeout, VkResult result) {
1828 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1829}
1830
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001831void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1832 VkResult result) {
1833 if (VK_SUCCESS != result) return;
1834
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001835 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001836 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001837 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001838 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001839}
1840
1841void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1842 VkResult result) {
1843 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1844}
1845void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1846 VkResult result) {
1847 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1848}
1849
locke-lunargd556cc32019-09-17 01:21:23 -06001850void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1851 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001852 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001853 if (fence_state) {
1854 fence_state->Retire();
1855 }
locke-lunargd556cc32019-09-17 01:21:23 -06001856}
1857
Yilong Lice03a312022-01-02 02:08:35 -08001858void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1859 if (Get<QUEUE_STATE>(queue) == nullptr) {
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001860 uint32_t num_queue_families = 0;
1861 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
1862 std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
1863 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
1864
1865 Add(CreateQueue(queue, queue_family_index, flags, queue_family_properties_list[queue_family_index]));
Yilong Lice03a312022-01-02 02:08:35 -08001866 }
1867}
1868
1869void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1870 VkQueue *pQueue) {
1871 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1872}
1873
1874void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1875 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1876}
1877
locke-lunargd556cc32019-09-17 01:21:23 -06001878void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1879 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001880 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001881 if (queue_state) {
1882 queue_state->Retire();
1883 }
locke-lunargd556cc32019-09-17 01:21:23 -06001884}
1885
1886void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1887 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001888 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001889 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001890 }
1891}
1892
1893void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001894 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001895}
1896
1897void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1898 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001899 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001900}
1901
1902void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001903 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001904}
1905
1906void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1907 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001908 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001909}
1910
locke-lunargd556cc32019-09-17 01:21:23 -06001911void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001912 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001913 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001914 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001915 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001916 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02001917 buffer_state->BindMemory(buffer_state.get(), mem_state, memoryOffset, 0u, buffer_state->requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001918 }
locke-lunargd556cc32019-09-17 01:21:23 -06001919 }
1920}
1921
1922void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1923 VkDeviceSize memoryOffset, VkResult result) {
1924 if (VK_SUCCESS != result) return;
1925 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1926}
1927
1928void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001929 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001930 for (uint32_t i = 0; i < bindInfoCount; i++) {
1931 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1932 }
1933}
1934
1935void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001936 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001937 for (uint32_t i = 0; i < bindInfoCount; i++) {
1938 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1939 }
1940}
1941
Spencer Fricke6c127102020-04-16 06:25:20 -07001942void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001943 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001944 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001945 buffer_state->memory_requirements_checked = true;
1946 }
1947}
1948
1949void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1950 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001951 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001952}
1953
1954void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001955 const VkBufferMemoryRequirementsInfo2 *pInfo,
1956 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001957 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001958}
1959
1960void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001961 const VkBufferMemoryRequirementsInfo2 *pInfo,
1962 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001963 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001964}
1965
Spencer Fricke6c127102020-04-16 06:25:20 -07001966void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001967 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001968 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001969 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001970 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001971 if (plane_info != nullptr) {
1972 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001973 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001974 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001975 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001976 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001977 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001978 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001979 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001980 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001981 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001982 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001983 }
locke-lunargd556cc32019-09-17 01:21:23 -06001984 }
1985}
1986
1987void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1988 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001989 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001990}
1991
1992void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1993 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001994 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001995}
1996
1997void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1998 const VkImageMemoryRequirementsInfo2 *pInfo,
1999 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002000 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002001}
2002
locke-lunargd556cc32019-09-17 01:21:23 -06002003void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
2004 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
2005 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002006 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06002007 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002008}
2009
2010void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002011 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2012 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002013 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002014 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002015}
2016
2017void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002018 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2019 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002020 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002021 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002022}
2023
2024void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2025 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002026 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06002027}
2028
2029void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2030 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002031 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002032}
2033
2034void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2035 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002036 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002037}
2038
2039void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2040 const VkAllocationCallbacks *pAllocator) {
2041 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002042 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002043 // Any bound cmd buffers are now invalid
2044 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002045 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2046 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2047 custom_border_color_sampler_count--;
2048 }
locke-lunargd556cc32019-09-17 01:21:23 -06002049 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06002050 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002051}
2052
2053void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2054 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002055 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002056}
2057
2058void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2059 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002060 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002061}
2062
locke-lunargd556cc32019-09-17 01:21:23 -06002063void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2064 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002065 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2066 if (pool) {
2067 pool->Free(commandBufferCount, pCommandBuffers);
2068 }
locke-lunargd556cc32019-09-17 01:21:23 -06002069}
2070
2071void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2072 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2073 VkResult result) {
2074 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002075 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002076 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06002077}
2078
2079void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2080 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2081 VkResult result) {
2082 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002083
2084 uint32_t index_count = 0, n_perf_pass = 0;
2085 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002086 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002087 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002088 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002089
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002090 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002091 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2092 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2093 switch (counter.scope) {
2094 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002095 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002096 break;
2097 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002098 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002099 break;
2100 default:
2101 break;
2102 }
2103 }
2104
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002105 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002106 }
2107
Jeremy Gebben082a9832021-10-28 13:40:11 -06002108 Add(std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb));
locke-lunargd556cc32019-09-17 01:21:23 -06002109
locke-lunargd556cc32019-09-17 01:21:23 -06002110}
2111
2112void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2113 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002114 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002115}
2116
2117void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2118 VkCommandPoolResetFlags flags, VkResult result) {
2119 if (VK_SUCCESS != result) return;
2120 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002121 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2122 if (pool) {
2123 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002124 }
2125}
2126
2127void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2128 VkResult result) {
2129 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002130 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002131 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002132 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002133 }
2134 }
2135}
2136
locke-lunargd556cc32019-09-17 01:21:23 -06002137void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2138 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002139 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002140}
2141
2142void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2143 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002144 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002145}
2146
2147void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2148 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2149 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002150 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002151}
2152
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002153std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2154 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2155 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2156 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2157}
2158
locke-lunargd556cc32019-09-17 01:21:23 -06002159bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2160 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2161 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002162 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002163 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002164 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2165 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2166 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2167 cgpl_state->pipe_state.reserve(count);
2168 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002169 const auto &create_info = pCreateInfos[i];
2170 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2171 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2172
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002173 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002174 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002175 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002176 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2177 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002178 } else {
2179 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2180 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2181 if (!is_graphics_lib && !has_link_info) {
2182 skip = true;
2183 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002184 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002185 cgpl_state->pipe_state.push_back(
2186 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002187 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002188 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002189}
2190
2191void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2192 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2193 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2194 VkResult result, void *cgpl_state_data) {
2195 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2196 // This API may create pipelines regardless of the return value
2197 for (uint32_t i = 0; i < count; i++) {
2198 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002199 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002200 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002201 }
2202 }
2203 cgpl_state->pipe_state.clear();
2204}
2205
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002206std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2207 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2208 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2209}
2210
locke-lunargd556cc32019-09-17 01:21:23 -06002211bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2212 const VkComputePipelineCreateInfo *pCreateInfos,
2213 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002214 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002215 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2216 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2217 ccpl_state->pipe_state.reserve(count);
2218 for (uint32_t i = 0; i < count; i++) {
2219 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002220 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002221 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002222 }
2223 return false;
2224}
2225
2226void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2227 const VkComputePipelineCreateInfo *pCreateInfos,
2228 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2229 VkResult result, void *ccpl_state_data) {
2230 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2231
2232 // This API may create pipelines regardless of the return value
2233 for (uint32_t i = 0; i < count; i++) {
2234 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002235 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002236 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002237 }
2238 }
2239 ccpl_state->pipe_state.clear();
2240}
2241
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002242std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2243 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2244 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2245}
2246
locke-lunargd556cc32019-09-17 01:21:23 -06002247bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2248 uint32_t count,
2249 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2250 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002251 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002252 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2253 crtpl_state->pipe_state.reserve(count);
2254 for (uint32_t i = 0; i < count; i++) {
2255 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002256 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002257 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002258 }
2259 return false;
2260}
2261
2262void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2263 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2264 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2265 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2266 // This API may create pipelines regardless of the return value
2267 for (uint32_t i = 0; i < count; i++) {
2268 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002269 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002270 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002271 }
2272 }
2273 crtpl_state->pipe_state.clear();
2274}
2275
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002276std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2277 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2278 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2279}
2280
sourav parmarcd5fb182020-07-17 12:58:44 -07002281bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2282 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002283 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2284 const VkAllocationCallbacks *pAllocator,
2285 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002286 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002287 crtpl_state->pipe_state.reserve(count);
2288 for (uint32_t i = 0; i < count; i++) {
2289 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002290 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002291 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002292 }
2293 return false;
2294}
2295
sourav parmarcd5fb182020-07-17 12:58:44 -07002296void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2297 VkPipelineCache pipelineCache, uint32_t count,
2298 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2299 const VkAllocationCallbacks *pAllocator,
2300 VkPipeline *pPipelines, VkResult result,
2301 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002302 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002303 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002304 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002305
2306 if (!operation_is_deferred) {
2307 for (uint32_t i = 0; i < count; i++) {
2308 if (pPipelines[i] != VK_NULL_HANDLE) {
2309 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2310 Add(std::move((crtpl_state->pipe_state)[i]));
2311 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002312 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002313 } else {
2314 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2315 if (wrap_handles) {
2316 deferredOperation = layer_data->Unwrap(deferredOperation);
2317 }
2318 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2319 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2320 if (find_res->first) {
2321 cleanup_fn = std::move(find_res->second);
2322 }
2323 auto &pipeline_states = crtpl_state->pipe_state;
2324 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2325 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2326 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2327 pipeline_states[i]->SetHandle(pipelines[i]);
2328 this->Add(std::move(pipeline_states[i]));
2329 }
2330 });
2331 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002332 }
2333 crtpl_state->pipe_state.clear();
2334}
2335
locke-lunargd556cc32019-09-17 01:21:23 -06002336void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2337 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2338 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002339 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002340 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2341 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002342 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002343 }
locke-lunargd556cc32019-09-17 01:21:23 -06002344}
2345
2346void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2347 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2348 const VkAllocationCallbacks *pAllocator,
2349 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2350 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002351 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002352}
2353
locke-lunargd556cc32019-09-17 01:21:23 -06002354void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2355 const VkAllocationCallbacks *pAllocator,
2356 VkPipelineLayout *pPipelineLayout, VkResult result) {
2357 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002358 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002359}
2360
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002361std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2362 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2363 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2364}
2365
locke-lunargd556cc32019-09-17 01:21:23 -06002366void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2367 const VkAllocationCallbacks *pAllocator,
2368 VkDescriptorPool *pDescriptorPool, VkResult result) {
2369 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002370 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002371}
2372
2373void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2374 VkDescriptorPoolResetFlags flags, VkResult result) {
2375 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002376 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2377 if (pool) {
2378 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002379 }
locke-lunargd556cc32019-09-17 01:21:23 -06002380}
2381
2382bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2383 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002384 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002385 // Always update common data
2386 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2387 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2388 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2389
2390 return false;
2391}
2392
2393// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2394void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2395 VkDescriptorSet *pDescriptorSets, VkResult result,
2396 void *ads_state_data) {
2397 if (VK_SUCCESS != result) return;
2398 // All the updates are contained in a single cvdescriptorset function
2399 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2400 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002401 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2402 if (pool_state) {
2403 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2404 }
locke-lunargd556cc32019-09-17 01:21:23 -06002405}
2406
2407void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2408 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002409 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2410 if (pool_state) {
2411 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002412 }
2413}
2414
2415void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2416 const VkWriteDescriptorSet *pDescriptorWrites,
2417 uint32_t descriptorCopyCount,
2418 const VkCopyDescriptorSet *pDescriptorCopies) {
2419 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2420 pDescriptorCopies);
2421}
2422
2423void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002424 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002425 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002426 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002427 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002428 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002429 }
2430}
2431
locke-lunargd556cc32019-09-17 01:21:23 -06002432void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2433 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002434 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002435 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002436
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002437 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002438}
2439
2440void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002441 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002442 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002443
2444 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002445}
2446
2447void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2448 VkResult result) {
2449 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002450 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2451 if (cb_state) {
2452 cb_state->Reset();
2453 }
locke-lunargd556cc32019-09-17 01:21:23 -06002454 }
2455}
2456
2457CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2458 // initially assume everything is static state
2459 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2460
2461 if (ds) {
2462 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002463 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002464 }
2465 }
locke-lunargd556cc32019-09-17 01:21:23 -06002466 return flags;
2467}
2468
2469// Validation cache:
2470// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002471
2472void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2473 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002474 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002475 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002476 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002477
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002478 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002479 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002480 const auto *raster_state = pipe_state->RasterizationState();
2481 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002482 const auto *viewport_state = pipe_state->ViewportState();
2483 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002484 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002485 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002486 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002487 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002488
2489 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002490 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2491 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002492 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002493 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002494 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002495 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002496 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002497 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002498
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002499 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002500 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2501 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2502 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002503 if (!has_dynamic_viewport_count) {
2504 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002505 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002506 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2507 // should become = ~uint32_t(0) if the other interpretation is correct.
2508 }
2509 }
2510 if (!has_dynamic_scissor_count) {
2511 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002512 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002513 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2514 // should become = ~uint32_t(0) if the other interpretation is correct.
2515 }
2516 }
locke-lunargd556cc32019-09-17 01:21:23 -06002517 }
Nathaniel Cesario62f03592022-07-11 09:19:20 -06002518 cb_state->BindPipeline(ConvertToLvlBindPoint(pipelineBindPoint), pipe_state.get());
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002519 if (!disabled[command_buffer_state]) {
2520 cb_state->AddChild(pipe_state);
2521 }
locke-lunargd556cc32019-09-17 01:21:23 -06002522}
2523
2524void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2525 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002526 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002527 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002528 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2529 cb_state->viewportMask |= bits;
2530 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002531
2532 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2533 for (size_t i = 0; i < viewportCount; ++i) {
2534 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2535 }
locke-lunargd556cc32019-09-17 01:21:23 -06002536}
2537
2538void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2539 uint32_t exclusiveScissorCount,
2540 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002541 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002542 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002543 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2544 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002545}
2546
2547void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2548 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002549 if (disabled[command_buffer_state]) return;
2550
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002551 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002552 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002553
2554 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002555 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002556 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002557 }
2558}
2559
2560void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2561 uint32_t viewportCount,
2562 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002563 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002564 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002565 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2566 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002567}
2568
2569void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2570 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2571 const VkAllocationCallbacks *pAllocator,
2572 VkAccelerationStructureNV *pAccelerationStructure,
2573 VkResult result) {
2574 if (VK_SUCCESS != result) return;
Aitor Camacho3294edd2022-05-16 22:34:19 +02002575 std::shared_ptr<ACCELERATION_STRUCTURE_STATE> state =
2576 std::make_shared<ACCELERATION_STRUCTURE_STATE_LINEAR>(device, *pAccelerationStructure, pCreateInfo);
2577 Add(std::move(state));
locke-lunargd556cc32019-09-17 01:21:23 -06002578}
2579
Jeff Bolz95176d02020-04-01 00:36:16 -05002580void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2581 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2582 const VkAllocationCallbacks *pAllocator,
2583 VkAccelerationStructureKHR *pAccelerationStructure,
2584 VkResult result) {
2585 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002586 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2587 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002588}
2589
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002590void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2591 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2592 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2593 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2594 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002595 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002596 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002597 dst_as_state->Build(&pInfos[i], true, *ppBuildRangeInfos);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002598 }
2599 }
2600}
2601
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002602// helper method for device side acceleration structure builds
2603void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2604 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2605 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2606 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002607 dst_as_state->Build(&info, false, nullptr);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002608 }
2609 if (disabled[command_buffer_state]) {
2610 return;
2611 }
2612 if (dst_as_state) {
2613 cb_state.AddChild(dst_as_state);
2614 }
2615 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2616 if (src_as_state) {
2617 cb_state.AddChild(src_as_state);
2618 }
2619 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2620 if (scratch_buffer) {
2621 cb_state.AddChild(scratch_buffer);
2622 }
2623
2624 for (uint32_t i = 0; i < info.geometryCount; i++) {
2625 // only one of pGeometries and ppGeometries can be non-null
2626 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2627 switch (geom.geometryType) {
2628 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2629 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2630 if (vertex_buffer) {
2631 cb_state.AddChild(vertex_buffer);
2632 }
2633 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2634 if (index_buffer) {
2635 cb_state.AddChild(index_buffer);
2636 }
2637 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2638 if (transform_buffer) {
2639 cb_state.AddChild(transform_buffer);
2640 }
2641 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2642 if (motion_data) {
2643 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2644 if (motion_buffer) {
2645 cb_state.AddChild(motion_buffer);
2646 }
2647 }
2648 } break;
2649 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2650 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2651 if (data_buffer) {
2652 cb_state.AddChild(data_buffer);
2653 }
2654 } break;
2655 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2656 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2657 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2658 // easily ensure that's true.
2659 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2660 if (data_buffer) {
2661 cb_state.AddChild(data_buffer);
2662 }
2663 } break;
2664 default:
2665 break;
2666 }
2667 }
2668}
2669
sourav parmarcd5fb182020-07-17 12:58:44 -07002670void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2671 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2672 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002673 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002674 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002675 return;
2676 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002677 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002678 for (uint32_t i = 0; i < infoCount; i++) {
2679 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002680 }
sjfricke52defd42022-08-08 16:37:46 +09002681 cb_state->has_build_as_cmd = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07002682}
2683
2684void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2685 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2686 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2687 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002688 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2689 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002690 return;
2691 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002692 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002693 for (uint32_t i = 0; i < infoCount; i++) {
2694 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002695 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002696 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2697 if (indirect_buffer) {
2698 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002699 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002700 }
2701 }
sjfricke52defd42022-08-08 16:37:46 +09002702 cb_state->has_build_as_cmd = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07002703}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002704
locke-lunargd556cc32019-09-17 01:21:23 -06002705void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002706 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002707 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002708 if (as_state != nullptr) {
2709 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002710 as_state->memory_requirements_checked = true;
2711 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002712 as_state->build_scratch_memory_requirements_checked = true;
2713 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002714 as_state->update_scratch_memory_requirements_checked = true;
2715 }
2716 }
2717}
2718
sourav parmarcd5fb182020-07-17 12:58:44 -07002719void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2720 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002721 if (VK_SUCCESS != result) return;
2722 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002723 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002724
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002725 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002726 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002727 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002728 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002729 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02002730 as_state->BindMemory(as_state.get(), mem_state, info.memoryOffset, 0u, as_state->memory_requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002731 }
locke-lunargd556cc32019-09-17 01:21:23 -06002732
2733 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002734 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002735 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002736 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2737 }
2738 }
2739 }
2740}
2741
2742void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2743 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2744 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002745 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2746 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002747 return;
2748 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002749 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002750
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002751 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002752 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002753 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002754 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002755 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002756 }
locke-lunargd556cc32019-09-17 01:21:23 -06002757 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002758 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002759 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002760 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002761 cb_state->AddChild(src_as_state);
2762 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002763 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2764 if (instance_buffer) {
2765 cb_state->AddChild(instance_buffer);
2766 }
2767 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2768 if (scratch_buffer) {
2769 cb_state->AddChild(scratch_buffer);
2770 }
2771
2772 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2773 const auto& geom = pInfo->pGeometries[i];
2774
2775 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2776 if (vertex_buffer) {
2777 cb_state->AddChild(vertex_buffer);
2778 }
2779 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2780 if (index_buffer) {
2781 cb_state->AddChild(index_buffer);
2782 }
2783 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2784 if (transform_buffer) {
2785 cb_state->AddChild(transform_buffer);
2786 }
2787
2788 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2789 if (aabb_buffer) {
2790 cb_state->AddChild(aabb_buffer);
2791 }
2792 }
2793
locke-lunargd556cc32019-09-17 01:21:23 -06002794 }
sjfricke52defd42022-08-08 16:37:46 +09002795 cb_state->has_build_as_cmd = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002796}
2797
2798void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2799 VkAccelerationStructureNV dst,
2800 VkAccelerationStructureNV src,
2801 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002802 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002803 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002804 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2805 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002806 if (!disabled[command_buffer_state]) {
2807 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2808 }
locke-lunargd556cc32019-09-17 01:21:23 -06002809 if (dst_as_state != nullptr && src_as_state != nullptr) {
2810 dst_as_state->built = true;
2811 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002812 }
2813 }
2814}
2815
Jeff Bolz95176d02020-04-01 00:36:16 -05002816void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2817 VkAccelerationStructureKHR accelerationStructure,
2818 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002819 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002820}
2821
Jeff Bolz95176d02020-04-01 00:36:16 -05002822void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2823 VkAccelerationStructureNV accelerationStructure,
2824 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002825 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002826}
2827
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002828void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2829 uint32_t viewportCount,
2830 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002831 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002832 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002833}
2834
locke-lunargd556cc32019-09-17 01:21:23 -06002835void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002836 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002837 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002838}
2839
2840void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2841 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002842 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002843 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002844}
2845
2846void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2847 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002848 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002849 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002850}
2851
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002852void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2853 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002854 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002855 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002856 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2857 cb_state->scissorMask |= bits;
2858 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002859}
2860
locke-lunargd556cc32019-09-17 01:21:23 -06002861void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002862 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002863 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002864}
2865
2866void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2867 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002868 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002869 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002870}
2871
2872void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2873 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002874 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002875 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002876}
2877
2878void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2879 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002880 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002881 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002882}
2883
2884void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2885 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002886 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002887 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002888}
2889
locke-lunargd556cc32019-09-17 01:21:23 -06002890// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2891void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2892 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2893 uint32_t firstSet, uint32_t setCount,
2894 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2895 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002896 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002897 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002898 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002899 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002900
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002901 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2902 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002903}
2904
locke-lunargd556cc32019-09-17 01:21:23 -06002905void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2906 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2907 uint32_t set, uint32_t descriptorWriteCount,
2908 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002909 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002910 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002911 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002912}
2913
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002914void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2915 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2916 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002917 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2918 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002919 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002920 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2921 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002922
2923 auto &push_constant_data = cb_state->push_constant_data;
2924 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2925 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002926 cb_state->push_constant_pipeline_layout_set = layout;
2927
2928 auto flags = stageFlags;
2929 uint32_t bit_shift = 0;
2930 while (flags) {
2931 if (flags & 1) {
2932 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2933 const auto it = cb_state->push_constant_data_update.find(flag);
2934
2935 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002936 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002937 }
2938 }
2939 flags = flags >> 1;
2940 ++bit_shift;
2941 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002942 }
2943}
2944
locke-lunargd556cc32019-09-17 01:21:23 -06002945void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2946 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002947 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002948
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002949 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002950 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002951 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002952 cb_state->index_buffer_binding.offset = offset;
2953 cb_state->index_buffer_binding.index_type = indexType;
2954 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002955 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002956 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002957 }
locke-lunargd556cc32019-09-17 01:21:23 -06002958}
2959
2960void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2961 uint32_t bindingCount, const VkBuffer *pBuffers,
2962 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002963 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002964 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002965
2966 uint32_t end = firstBinding + bindingCount;
2967 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2968 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2969 }
2970
2971 for (uint32_t i = 0; i < bindingCount; ++i) {
2972 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002973 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002974 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002975 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2976 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002977 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002978 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002979 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002980 }
locke-lunargd556cc32019-09-17 01:21:23 -06002981 }
2982}
2983
2984void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2985 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002986 if (disabled[command_buffer_state]) return;
2987
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002988 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002989 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002990}
2991
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002992void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2993 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002994 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002995 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002996}
2997
2998void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2999 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003000 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003001 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3002
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003003 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
3004 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003005}
3006
Tony-LunarGc43525f2021-11-15 16:12:38 -07003007void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3008 const VkDependencyInfo* pDependencyInfo) {
3009 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3010 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3011
3012 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
3013 cb_state->RecordBarriers(*pDependencyInfo);
3014}
3015
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003016void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3017 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003018 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003019 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003020}
3021
3022void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3023 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003024 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003025 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003026}
3027
Tony-LunarGa2662db2021-11-16 07:26:24 -07003028void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3029 VkPipelineStageFlags2 stageMask) {
3030 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3031 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
3032}
3033
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003034void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3035 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
3036 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3037 uint32_t bufferMemoryBarrierCount,
3038 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3039 uint32_t imageMemoryBarrierCount,
3040 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003041 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3042 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003043 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3044 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003045}
3046
3047void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3048 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003049 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06003050 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003051 const auto &dep_info = pDependencyInfos[i];
3052 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3053 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
3054 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06003055 }
3056}
3057
Tony-LunarG1364cf52021-11-17 16:10:11 -07003058void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3059 const VkDependencyInfo *pDependencyInfos) {
3060 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3061 for (uint32_t i = 0; i < eventCount; i++) {
3062 const auto &dep_info = pDependencyInfos[i];
3063 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3064 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
3065 cb_state->RecordBarriers(dep_info);
3066 }
3067}
3068
Jeremy Gebben79649152021-06-22 14:46:24 -06003069void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3070 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3071 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3072 uint32_t bufferMemoryBarrierCount,
3073 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3074 uint32_t imageMemoryBarrierCount,
3075 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003076 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003077 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3078 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3079 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003080}
3081
3082void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3083 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003084 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003085 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3086 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003087}
3088
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07003089void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
3090 const VkDependencyInfo *pDependencyInfo) {
3091 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3092 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
3093 cb_state->RecordBarriers(*pDependencyInfo);
3094}
3095
locke-lunargd556cc32019-09-17 01:21:23 -06003096void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3097 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003098 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003099 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02003100
3101 uint32_t num_queries = 1;
3102 // If render pass instance has multiview enabled, query uses N consecutive query indices
3103 if (cb_state->activeRenderPass) {
3104 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
3105 num_queries = std::max(num_queries, bits);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003106 }
ziga-lunarg9ad42712022-08-21 03:01:29 +02003107 for (uint32_t i = 0; i < num_queries; ++i) {
3108 QueryObject query = {queryPool, slot};
3109 cb_state->RecordCmd(CMD_BEGINQUERY);
3110 if (!disabled[query_validation]) {
3111 cb_state->BeginQuery(query);
3112 }
3113 if (!disabled[command_buffer_state]) {
3114 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
3115 cb_state->AddChild(pool_state);
3116 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003117 }
locke-lunargd556cc32019-09-17 01:21:23 -06003118}
3119
3120void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003121 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003122 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02003123 uint32_t num_queries = 1;
3124 // If render pass instance has multiview enabled, query uses N consecutive query indices
3125 if (cb_state->activeRenderPass) {
3126 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
3127 num_queries = std::max(num_queries, bits);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003128 }
ziga-lunarg9ad42712022-08-21 03:01:29 +02003129
3130 for (uint32_t i = 0; i < num_queries; ++i) {
3131 QueryObject query_obj = {queryPool, slot + i};
3132 cb_state->RecordCmd(CMD_ENDQUERY);
3133 if (!disabled[query_validation]) {
3134 cb_state->EndQuery(query_obj);
3135 }
3136 if (!disabled[command_buffer_state]) {
3137 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
3138 cb_state->AddChild(pool_state);
3139 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003140 }
locke-lunargd556cc32019-09-17 01:21:23 -06003141}
3142
3143void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3144 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003145 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003146 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003147
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003148 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003149 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003150
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003151 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003152 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003153 cb_state->AddChild(pool_state);
3154 }
locke-lunargd556cc32019-09-17 01:21:23 -06003155}
3156
3157void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3158 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3159 VkDeviceSize dstOffset, VkDeviceSize stride,
3160 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003161 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3162
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003163 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003164 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003165 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003166 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003167 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003168 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003169}
3170
3171void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3172 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003173 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003174 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003175}
3176
3177void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3178 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3179 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003180 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003181 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003182}
3183
Tony-LunarGde9936b2021-11-17 15:34:11 -07003184void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3185 VkQueryPool queryPool, uint32_t slot) {
3186 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3187 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3188}
3189
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003190void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3191 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3192 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3193 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003194 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003195 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003196 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003197 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003198 cb_state->AddChild(pool_state);
3199 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003200 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003201}
3202
locke-lunargd556cc32019-09-17 01:21:23 -06003203void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3204 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3205 VkResult result) {
3206 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003207
Jeremy Gebben88f58142021-06-01 10:07:52 -06003208 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003209 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003210 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003211
locke-lunargd556cc32019-09-17 01:21:23 -06003212 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003213 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003214 }
3215 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003216
Jeremy Gebben9f537102021-10-05 16:37:12 -06003217 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003218 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003219}
3220
locke-lunargd556cc32019-09-17 01:21:23 -06003221void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3222 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3223 VkResult result) {
3224 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003225 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003226}
3227
Mike Schuchardt2df08912020-12-15 16:28:09 -08003228void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003229 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3230 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003231 if (VK_SUCCESS != result) return;
3232
Jeremy Gebben082a9832021-10-28 13:40:11 -06003233 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003234}
3235
Mike Schuchardt2df08912020-12-15 16:28:09 -08003236void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003237 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3238 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003239 if (VK_SUCCESS != result) return;
3240
Jeremy Gebben082a9832021-10-28 13:40:11 -06003241 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003242}
3243
locke-lunargd556cc32019-09-17 01:21:23 -06003244void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3245 const VkRenderPassBeginInfo *pRenderPassBegin,
3246 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003247 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003248 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003249}
3250
3251void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3252 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003253 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003254 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003255 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003256}
3257
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003258void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3259 uint32_t counterBufferCount,
3260 const VkBuffer *pCounterBuffers,
3261 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003262 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003263
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003264 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003265 cb_state->transform_feedback_active = true;
3266}
3267
3268void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3269 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3270 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003271 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003272
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003273 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003274 cb_state->transform_feedback_active = false;
3275}
3276
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003277void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3278 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003279 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003280
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003281 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003282 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003283 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3284 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003285}
3286
3287void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003288 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003289
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003290 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003291 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003292 cb_state->conditional_rendering_inside_render_pass = false;
3293 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003294}
3295
amhagana448ea52021-11-02 14:09:14 -04003296void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003297 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003298 cb_state->activeRenderPass = nullptr;
3299}
3300
3301void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3302 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003303 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003304 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3305}
3306
Tony-LunarG40b33882021-12-02 12:40:11 -07003307void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3308 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3309 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3310}
3311
amhagana448ea52021-11-02 14:09:14 -04003312void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3313 RecordCmdEndRenderingRenderPassState(commandBuffer);
3314}
3315
Tony-LunarG40b33882021-12-02 12:40:11 -07003316void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3317 RecordCmdEndRenderingRenderPassState(commandBuffer);
3318}
3319
Tony-LunarG977448c2019-12-02 14:52:02 -07003320void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3321 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003322 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003323 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003324 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003325}
3326
locke-lunargd556cc32019-09-17 01:21:23 -06003327void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003328 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003329 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003330}
3331
3332void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003333 const VkSubpassBeginInfo *pSubpassBeginInfo,
3334 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003335 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003336 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003337}
3338
Tony-LunarG977448c2019-12-02 14:52:02 -07003339void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003340 const VkSubpassBeginInfo *pSubpassBeginInfo,
3341 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003342 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003343 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003344}
3345
3346void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003347 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003348 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003349}
3350
3351void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003352 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003353 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003354 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003355}
3356
Tony-LunarG977448c2019-12-02 14:52:02 -07003357void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003358 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003359 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003360 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003361}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003362
locke-lunargd556cc32019-09-17 01:21:23 -06003363void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3364 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003365 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003366
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003367 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003368}
3369
3370void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3371 VkFlags flags, void **ppData, VkResult result) {
3372 if (VK_SUCCESS != result) return;
3373 RecordMappedMemory(mem, offset, size, ppData);
3374}
3375
3376void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003377 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003378 if (mem_info) {
3379 mem_info->mapped_range = MemRange();
3380 mem_info->p_driver_data = nullptr;
3381 }
3382}
3383
3384void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003385 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003386 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003387 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3388 // See: VUID-vkGetImageSubresourceLayout-image-01895
3389 image_state->fragment_encoder =
3390 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003391 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003392 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003393 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003394 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003395 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003396
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003397 if (!swapchain_image.fake_base_address) {
3398 auto size = image_state->fragment_encoder->TotalSize();
3399 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003400 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003401 // All images bound to this swapchain and index are aliases
3402 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003403 }
3404 } else {
3405 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003406 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003407 if (mem_info) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02003408 VkDeviceSize plane_index = 0u;
3409 if (image_state->disjoint && image_state->IsExternalAHB() == false) {
3410 auto plane_info = LvlFindInChain<VkBindImagePlaneMemoryInfo>(bindInfo.pNext);
3411 const VkImageAspectFlagBits aspect = plane_info->planeAspect;
3412 switch (aspect) {
3413 case VK_IMAGE_ASPECT_PLANE_0_BIT:
3414 plane_index = 0;
3415 break;
3416 case VK_IMAGE_ASPECT_PLANE_1_BIT:
3417 plane_index = 1;
3418 break;
3419 case VK_IMAGE_ASPECT_PLANE_2_BIT:
3420 plane_index = 2;
3421 break;
3422 default:
3423 assert(false); // parameter validation should have caught this
3424 break;
3425 }
3426 }
3427 image_state->BindMemory(
3428 image_state.get(), mem_info, bindInfo.memoryOffset, plane_index,
3429 image_state->requirements[static_cast<decltype(image_state->requirements)::size_type>(plane_index)].size);
locke-lunargd556cc32019-09-17 01:21:23 -06003430 }
locke-lunargd556cc32019-09-17 01:21:23 -06003431 }
locke-lunargd556cc32019-09-17 01:21:23 -06003432 }
3433}
3434
3435void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3436 VkDeviceSize memoryOffset, VkResult result) {
3437 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003438 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003439 bind_info.image = image;
3440 bind_info.memory = mem;
3441 bind_info.memoryOffset = memoryOffset;
3442 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003443}
3444
3445void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003446 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003447 if (VK_SUCCESS != result) return;
3448 for (uint32_t i = 0; i < bindInfoCount; i++) {
3449 UpdateBindImageMemoryState(pBindInfos[i]);
3450 }
3451}
3452
3453void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003454 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003455 if (VK_SUCCESS != result) return;
3456 for (uint32_t i = 0; i < bindInfoCount; i++) {
3457 UpdateBindImageMemoryState(pBindInfos[i]);
3458 }
3459}
3460
3461void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003462 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003463 if (event_state) {
3464 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3465 }
locke-lunargd556cc32019-09-17 01:21:23 -06003466}
3467
3468void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3469 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3470 VkResult result) {
3471 if (VK_SUCCESS != result) return;
3472 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3473 pImportSemaphoreFdInfo->flags);
3474}
3475
3476void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003477 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003478 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003479 if (semaphore_state) {
3480 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003481 }
3482}
3483
3484#ifdef VK_USE_PLATFORM_WIN32_KHR
3485void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3486 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3487 if (VK_SUCCESS != result) return;
3488 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3489 pImportSemaphoreWin32HandleInfo->flags);
3490}
3491
3492void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3493 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3494 HANDLE *pHandle, VkResult result) {
3495 if (VK_SUCCESS != result) return;
3496 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3497}
3498
3499void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3500 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3501 if (VK_SUCCESS != result) return;
3502 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3503 pImportFenceWin32HandleInfo->flags);
3504}
3505
3506void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3507 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3508 HANDLE *pHandle, VkResult result) {
3509 if (VK_SUCCESS != result) return;
3510 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3511}
3512#endif
3513
3514void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3515 VkResult result) {
3516 if (VK_SUCCESS != result) return;
3517 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3518}
3519
Mike Schuchardt2df08912020-12-15 16:28:09 -08003520void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3521 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003522 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003523
3524 if (fence_node) {
3525 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003526 }
3527}
3528
3529void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3530 VkResult result) {
3531 if (VK_SUCCESS != result) return;
3532 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3533}
3534
Mike Schuchardt2df08912020-12-15 16:28:09 -08003535void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003536 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003537 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003538 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003539 }
3540}
3541
3542void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3543 VkResult result) {
3544 if (VK_SUCCESS != result) return;
3545 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3546}
3547
3548void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3549 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3550 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06003551 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003552}
3553
3554void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003555 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003556 SWAPCHAIN_NODE *old_swapchain_state) {
3557 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003558 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003559 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003560 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003561 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3562 surface_state->AddParent(swapchain.get());
3563 surface_state->swapchain = swapchain.get();
3564 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003565 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003566 } else {
3567 surface_state->swapchain = nullptr;
3568 }
3569 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003570 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003571 if (old_swapchain_state) {
3572 old_swapchain_state->retired = true;
3573 }
3574 return;
3575}
3576
3577void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3578 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3579 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003580 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003581 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003582 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003583}
3584
3585void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3586 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003587 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003588}
3589
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003590void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3591 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3592 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3593 VkResult result) {
3594 if (VK_SUCCESS != result) return;
3595 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003596 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003597}
3598
locke-lunargd556cc32019-09-17 01:21:23 -06003599void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003600 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003601 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003602 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3603 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3604 if (semaphore_state) {
3605 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003606 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003607 }
3608
3609 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3610 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3611 // 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
3612 // confused itself just as much.
3613 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3614 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3615 // Mark the image as having been released to the WSI
3616 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3617 if (swapchain_data) {
3618 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3619 if (present_id_info) {
3620 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3621 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3622 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003623 }
3624 }
locke-lunargd556cc32019-09-17 01:21:23 -06003625 }
locke-lunargd556cc32019-09-17 01:21:23 -06003626}
3627
3628void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3629 const VkSwapchainCreateInfoKHR *pCreateInfos,
3630 const VkAllocationCallbacks *pAllocator,
3631 VkSwapchainKHR *pSwapchains, VkResult result) {
3632 if (pCreateInfos) {
3633 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003634 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003635 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003636 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3637 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003638 }
3639 }
3640}
3641
3642void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3643 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003644 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003645 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003646 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3647 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003648 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003649 }
3650
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003651 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003652 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003653 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3654 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003655 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003656 }
3657
3658 // Mark the image as acquired.
3659 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3660 if (swapchain_data) {
3661 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003662 }
3663}
3664
3665void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3666 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3667 VkResult result) {
3668 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3669 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3670}
3671
3672void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3673 uint32_t *pImageIndex, VkResult result) {
3674 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3675 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3676 pAcquireInfo->fence, pImageIndex);
3677}
3678
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003679std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3680 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3681}
3682
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003683void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3684 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3685 VkResult result) {
3686 if (result != VK_SUCCESS) {
3687 return;
3688 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003689 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003690 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003691 // this can fail if the allocator fails
3692 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3693 if (result != VK_SUCCESS) {
3694 return;
3695 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003696 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003697 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3698 if (result != VK_SUCCESS) {
3699 return;
3700 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003701
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003702 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003703 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003704 }
Tony-LunarGffb5b522022-06-15 15:49:27 -06003705
3706#ifdef VK_USE_PLATFORM_METAL_EXT
3707 auto export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(pCreateInfo->pNext);
3708 while (export_metal_object_info) {
3709 export_metal_flags.push_back(export_metal_object_info->exportObjectType);
3710 export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(export_metal_object_info->pNext);
3711 }
3712#endif // VK_USE_PLATFORM_METAL_EXT
locke-lunargd556cc32019-09-17 01:21:23 -06003713}
3714
Tony-LunarGffb5b522022-06-15 15:49:27 -06003715
locke-lunargd556cc32019-09-17 01:21:23 -06003716// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003717static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003718 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003719}
3720
3721void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3722 uint32_t *pQueueFamilyPropertyCount,
3723 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003724 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3725 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003726 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003727}
3728
3729void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003730 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003731 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3732 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003733 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003734}
3735
3736void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003737 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003738 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3739 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003740 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003741}
3742void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3743 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003744 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003745}
3746
Jeremy Gebben082a9832021-10-28 13:40:11 -06003747void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003748
3749void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3750 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3751 const VkAllocationCallbacks *pAllocator,
3752 VkSurfaceKHR *pSurface, VkResult result) {
3753 if (VK_SUCCESS != result) return;
3754 RecordVulkanSurface(pSurface);
3755}
3756
3757#ifdef VK_USE_PLATFORM_ANDROID_KHR
3758void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3759 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3760 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3761 VkResult result) {
3762 if (VK_SUCCESS != result) return;
3763 RecordVulkanSurface(pSurface);
3764}
3765#endif // VK_USE_PLATFORM_ANDROID_KHR
3766
3767#ifdef VK_USE_PLATFORM_IOS_MVK
3768void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3769 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3770 VkResult result) {
3771 if (VK_SUCCESS != result) return;
3772 RecordVulkanSurface(pSurface);
3773}
3774#endif // VK_USE_PLATFORM_IOS_MVK
3775
3776#ifdef VK_USE_PLATFORM_MACOS_MVK
3777void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3778 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3779 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3780 VkResult result) {
3781 if (VK_SUCCESS != result) return;
3782 RecordVulkanSurface(pSurface);
3783}
3784#endif // VK_USE_PLATFORM_MACOS_MVK
3785
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003786#ifdef VK_USE_PLATFORM_METAL_EXT
3787void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3788 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3789 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3790 VkResult result) {
3791 if (VK_SUCCESS != result) return;
3792 RecordVulkanSurface(pSurface);
3793}
3794#endif // VK_USE_PLATFORM_METAL_EXT
3795
locke-lunargd556cc32019-09-17 01:21:23 -06003796#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3797void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3798 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3799 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3800 VkResult result) {
3801 if (VK_SUCCESS != result) return;
3802 RecordVulkanSurface(pSurface);
3803}
3804#endif // VK_USE_PLATFORM_WAYLAND_KHR
3805
3806#ifdef VK_USE_PLATFORM_WIN32_KHR
3807void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3808 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3809 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3810 VkResult result) {
3811 if (VK_SUCCESS != result) return;
3812 RecordVulkanSurface(pSurface);
3813}
3814#endif // VK_USE_PLATFORM_WIN32_KHR
3815
3816#ifdef VK_USE_PLATFORM_XCB_KHR
3817void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3818 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3819 VkResult result) {
3820 if (VK_SUCCESS != result) return;
3821 RecordVulkanSurface(pSurface);
3822}
3823#endif // VK_USE_PLATFORM_XCB_KHR
3824
3825#ifdef VK_USE_PLATFORM_XLIB_KHR
3826void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3827 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3828 VkResult result) {
3829 if (VK_SUCCESS != result) return;
3830 RecordVulkanSurface(pSurface);
3831}
3832#endif // VK_USE_PLATFORM_XLIB_KHR
3833
Niklas Haas8b84af12020-04-19 22:20:11 +02003834void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3835 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3836 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3837 VkResult result) {
3838 if (VK_SUCCESS != result) return;
3839 RecordVulkanSurface(pSurface);
3840}
3841
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003842void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3843 VkSurfaceKHR surface,
3844 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3845 VkResult result) {
3846 if (VK_SUCCESS != result) return;
3847 auto surface_state = Get<SURFACE_STATE>(surface);
3848 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3849}
3850
3851void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3852 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3853 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3854 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003855
3856 if (pSurfaceInfo->surface) {
3857 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3858 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3859 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3860 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3861 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3862 assert(pd_state);
3863 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3864 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003865}
3866
3867void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3868 VkSurfaceKHR surface,
3869 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3870 VkResult result) {
3871 auto surface_state = Get<SURFACE_STATE>(surface);
3872 VkSurfaceCapabilitiesKHR caps{
3873 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3874 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3875 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3876 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3877 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3878 };
3879 surface_state->SetCapabilities(physicalDevice, caps);
3880}
3881
locke-lunargd556cc32019-09-17 01:21:23 -06003882void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3883 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3884 VkBool32 *pSupported, VkResult result) {
3885 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003886 auto surface_state = Get<SURFACE_STATE>(surface);
3887 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3888}
3889
3890void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3891 VkSurfaceKHR surface,
3892 uint32_t *pPresentModeCount,
3893 VkPresentModeKHR *pPresentModes,
3894 VkResult result) {
3895 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3896
3897 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003898 if (surface) {
3899 auto surface_state = Get<SURFACE_STATE>(surface);
3900 surface_state->SetPresentModes(physicalDevice,
3901 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3902 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3903 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3904 assert(pd_state);
3905 pd_state->surfaceless_query_state.present_modes =
3906 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3907 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003908 }
3909}
3910
3911void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3912 uint32_t *pSurfaceFormatCount,
3913 VkSurfaceFormatKHR *pSurfaceFormats,
3914 VkResult result) {
3915 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3916
3917 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003918 if (surface) {
3919 auto surface_state = Get<SURFACE_STATE>(surface);
3920 surface_state->SetFormats(physicalDevice,
3921 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3922 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3923 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3924 assert(pd_state);
3925 pd_state->surfaceless_query_state.formats =
3926 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3927 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003928 }
3929}
3930
3931void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3932 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3933 uint32_t *pSurfaceFormatCount,
3934 VkSurfaceFormat2KHR *pSurfaceFormats,
3935 VkResult result) {
3936 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3937
3938 if (pSurfaceFormats) {
3939 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003940 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3941 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3942 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003943 if (pSurfaceInfo->surface) {
3944 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3945 surface_state->SetFormats(physicalDevice, std::move(fmts));
3946 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3947 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3948 assert(pd_state);
3949 pd_state->surfaceless_query_state.formats = std::move(fmts);
3950 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003951 }
locke-lunargd556cc32019-09-17 01:21:23 -06003952}
3953
locke-lunargd556cc32019-09-17 01:21:23 -06003954void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3955 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003956 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003957 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003958 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3959}
3960
3961void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003962 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003963 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003964 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3965}
3966
3967void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3968 const VkDebugUtilsLabelEXT *pLabelInfo) {
3969 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3970
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003971 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003972 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3973 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003974 cb_state->debug_label = LoggingLabel(pLabelInfo);
3975}
3976
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003977void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3978 uint32_t queueFamilyIndex,
3979 uint32_t *pCounterCount,
3980 VkPerformanceCounterKHR *pCounters) {
3981 if (NULL == pCounters) return;
3982
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003983 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3984 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003985
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003986 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3987 queue_family_counters->counters.resize(*pCounterCount);
3988 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003989
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003990 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003991}
3992
3993void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3994 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3995 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3996 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3997 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3998}
3999
4000void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
4001 VkResult result) {
4002 if (result == VK_SUCCESS) performance_lock_acquired = true;
4003}
4004
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004005void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
4006 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06004007 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004008 cmd_buffer.second->performance_lock_released = true;
4009 }
4010}
4011
locke-lunargd556cc32019-09-17 01:21:23 -06004012void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004013 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004014 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004015 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004016}
4017
4018void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004019 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004020 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004021 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004022}
4023
Mike Schuchardt2df08912020-12-15 16:28:09 -08004024void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4025 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004026 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06004027}
4028
Mike Schuchardt2df08912020-12-15 16:28:09 -08004029void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
4030 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4031 const VkAllocationCallbacks *pAllocator,
4032 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
4033 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004034 if (VK_SUCCESS != result) return;
4035 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4036}
4037
4038void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08004039 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4040 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004041 if (VK_SUCCESS != result) return;
4042 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4043}
4044
4045void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004046 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004047 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004048 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
4049 assert(template_state);
4050 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06004051 // TODO: Record template push descriptor updates
4052 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004053 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06004054 }
4055 }
4056}
4057
4058void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
4059 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4060 const void *pData) {
4061 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4062}
4063
4064void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004065 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004066 const void *pData) {
4067 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4068}
4069
Mike Schuchardt2df08912020-12-15 16:28:09 -08004070void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
4071 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4072 VkPipelineLayout layout, uint32_t set,
4073 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004074 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004075
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004076 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07004077 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004078 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004079 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06004080 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004081 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004082 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06004083 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004084 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06004085 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004086 static_cast<uint32_t>(decoded_template.desc_writes.size()),
4087 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06004088 }
4089}
4090
4091void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
4092 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004093 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06004094 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004095 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004096 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06004097 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004098 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004099 }
4100}
4101
4102void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
4103 uint32_t *pPropertyCount,
4104 VkDisplayPlanePropertiesKHR *pProperties,
4105 VkResult result) {
4106 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4107 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4108}
4109
4110void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
4111 uint32_t *pPropertyCount,
4112 VkDisplayPlaneProperties2KHR *pProperties,
4113 VkResult result) {
4114 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4115 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4116}
4117
4118void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4119 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004120 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02004121 uint32_t num_queries = 1;
4122 // If render pass instance has multiview enabled, query uses N consecutive query indices
4123 if (cb_state->activeRenderPass) {
4124 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
4125 num_queries = std::max(num_queries, bits);
4126 }
4127
4128 for (uint32_t i = 0; i < num_queries; ++i) {
4129 QueryObject query_obj = {queryPool, query, index + i};
4130 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
4131 cb_state->BeginQuery(query_obj);
4132 }
locke-lunargd556cc32019-09-17 01:21:23 -06004133}
4134
4135void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4136 uint32_t query, uint32_t index) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004137 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02004138 uint32_t num_queries = 1;
4139 // If render pass instance has multiview enabled, query uses N consecutive query indices
4140 if (cb_state->activeRenderPass) {
4141 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
4142 num_queries = std::max(num_queries, bits);
4143 }
4144
4145 for (uint32_t i = 0; i < num_queries; ++i) {
4146 QueryObject query_obj = {queryPool, query, index + i};
4147 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
4148 cb_state->EndQuery(query_obj);
4149 }
locke-lunargd556cc32019-09-17 01:21:23 -06004150}
4151
4152void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4153 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02004154 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004155
4156 if (create_info->format != VK_FORMAT_UNDEFINED) {
4157 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07004158 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004159 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4160 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004161 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004162
Jeremy Gebben082a9832021-10-28 13:40:11 -06004163 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004164}
4165
4166void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4167 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4168 const VkAllocationCallbacks *pAllocator,
4169 VkSamplerYcbcrConversion *pYcbcrConversion,
4170 VkResult result) {
4171 if (VK_SUCCESS != result) return;
4172 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4173}
4174
4175void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4176 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4177 const VkAllocationCallbacks *pAllocator,
4178 VkSamplerYcbcrConversion *pYcbcrConversion,
4179 VkResult result) {
4180 if (VK_SUCCESS != result) return;
4181 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4182}
4183
4184void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4185 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004186 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004187}
4188
4189void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4190 VkSamplerYcbcrConversion ycbcrConversion,
4191 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004192 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004193}
4194
Tony-LunarG977448c2019-12-02 14:52:02 -07004195void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4196 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004197 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004198 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004199
4200 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004201 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004202 if (!query_pool_state) return;
4203
4204 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004205 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4206 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004207 auto query_index = firstQuery + i;
4208 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004209 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004210 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004211 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004212 }
4213 }
locke-lunargd556cc32019-09-17 01:21:23 -06004214 }
4215}
4216
Tony-LunarG977448c2019-12-02 14:52:02 -07004217void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4218 uint32_t queryCount) {
4219 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4220}
4221
4222void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4223 uint32_t queryCount) {
4224 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4225}
4226
locke-lunargd556cc32019-09-17 01:21:23 -06004227void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004228 const UPDATE_TEMPLATE_STATE *template_state,
4229 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004230 // Translate the templated update into a normal update for validation...
4231 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4232 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4233 decoded_update.desc_writes.data(), 0, NULL);
4234}
4235
4236// Update the common AllocateDescriptorSetsData
4237void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004238 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004239 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004240 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004241 if (layout) {
4242 ds_data->layout_nodes[i] = layout;
4243 // Count total descriptors required per type
4244 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4245 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004246 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4247 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004248 }
4249 }
4250 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4251 }
4252}
4253
locke-lunargd556cc32019-09-17 01:21:23 -06004254void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4255 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004256 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004257 cb_state->UpdateDrawCmd(CMD_DRAW);
locke-lunargd556cc32019-09-17 01:21:23 -06004258}
4259
Tony-LunarG745150c2021-07-02 15:07:31 -06004260void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4261 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4262 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004263 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004264 cb_state->UpdateDrawCmd(CMD_DRAWMULTIEXT);
Tony-LunarG745150c2021-07-02 15:07:31 -06004265}
4266
locke-lunargd556cc32019-09-17 01:21:23 -06004267void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4268 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4269 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004270 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004271 cb_state->UpdateDrawCmd(CMD_DRAWINDEXED);
locke-lunargd556cc32019-09-17 01:21:23 -06004272}
4273
Tony-LunarG745150c2021-07-02 15:07:31 -06004274void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4275 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4276 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4277 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004278 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004279 cb_state->UpdateDrawCmd(CMD_DRAWMULTIINDEXEDEXT);
Tony-LunarG745150c2021-07-02 15:07:31 -06004280}
4281
locke-lunargd556cc32019-09-17 01:21:23 -06004282void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4283 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004284 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004285 auto buffer_state = Get<BUFFER_STATE>(buffer);
sjfricke52defd42022-08-08 16:37:46 +09004286 cb_state->UpdateDrawCmd(CMD_DRAWINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004287 if (!disabled[command_buffer_state]) {
4288 cb_state->AddChild(buffer_state);
4289 }
locke-lunargd556cc32019-09-17 01:21:23 -06004290}
4291
4292void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4293 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004294 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004295 auto buffer_state = Get<BUFFER_STATE>(buffer);
sjfricke52defd42022-08-08 16:37:46 +09004296 cb_state->UpdateDrawCmd(CMD_DRAWINDEXEDINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004297 if (!disabled[command_buffer_state]) {
4298 cb_state->AddChild(buffer_state);
4299 }
locke-lunargd556cc32019-09-17 01:21:23 -06004300}
4301
4302void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004303 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004304 cb_state->UpdateDispatchCmd(CMD_DISPATCH);
locke-lunargd556cc32019-09-17 01:21:23 -06004305}
4306
4307void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4308 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004309 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004310 cb_state->UpdateDispatchCmd(CMD_DISPATCHINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004311 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004312 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004313 cb_state->AddChild(buffer_state);
4314 }
locke-lunargd556cc32019-09-17 01:21:23 -06004315}
4316
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004317void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4318 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004319 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004320 cb_state->UpdateDispatchCmd(CMD_DISPATCHBASEKHR);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004321}
4322
4323void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4324 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004325 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004326 cb_state->UpdateDispatchCmd(CMD_DISPATCHBASE);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004327}
4328
Tony-LunarG977448c2019-12-02 14:52:02 -07004329void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4330 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004331 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004332 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004333 cb_state->UpdateDrawCmd(cmd_type);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004334 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004335 auto buffer_state = Get<BUFFER_STATE>(buffer);
4336 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004337 cb_state->AddChild(buffer_state);
4338 cb_state->AddChild(count_buffer_state);
4339 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004340}
4341
locke-lunargd556cc32019-09-17 01:21:23 -06004342void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4343 VkDeviceSize offset, VkBuffer countBuffer,
4344 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4345 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004346 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004347 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004348}
4349
4350void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4351 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4352 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004353 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004354 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004355}
4356
4357void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4358 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004359 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004360 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004361 cb_state->UpdateDrawCmd(cmd_type);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004362 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004363 auto buffer_state = Get<BUFFER_STATE>(buffer);
4364 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004365 cb_state->AddChild(buffer_state);
4366 cb_state->AddChild(count_buffer_state);
4367 }
locke-lunargd556cc32019-09-17 01:21:23 -06004368}
4369
4370void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4371 VkDeviceSize offset, VkBuffer countBuffer,
4372 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4373 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004374 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004375 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004376}
4377
4378void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4379 VkDeviceSize offset, VkBuffer countBuffer,
4380 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4381 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004382 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004383 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004384}
4385
4386void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4387 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004388 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004389 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSNV);
locke-lunargd556cc32019-09-17 01:21:23 -06004390}
4391
4392void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4393 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004394 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004395 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTNV);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004396 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004397 if (!disabled[command_buffer_state] && buffer_state) {
4398 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004399 }
4400}
4401
4402void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4403 VkDeviceSize offset, VkBuffer countBuffer,
4404 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4405 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004406 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004407 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTCOUNTNV);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004408 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004409 auto buffer_state = Get<BUFFER_STATE>(buffer);
4410 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004411 if (buffer_state) {
4412 cb_state->AddChild(buffer_state);
4413 }
4414 if (count_buffer_state) {
4415 cb_state->AddChild(count_buffer_state);
4416 }
locke-lunargd556cc32019-09-17 01:21:23 -06004417 }
4418}
4419
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004420void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4421 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4422 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4423 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4424 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4425 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4426 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004427 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004428 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSNV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004429}
4430
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004431void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4432 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4433 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4434 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4435 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4436 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004437 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004438 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSKHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004439}
4440
4441void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4442 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4443 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4444 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4445 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4446 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004447 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004448 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECTKHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004449}
4450
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004451std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4452 uint32_t unique_shader_id) const {
4453 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4454 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4455 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4456 : std::make_shared<SHADER_MODULE_STATE>();
4457}
4458
4459std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4460 uint32_t unique_shader_id,
4461 VkShaderModule handle) const {
4462 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4463 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4464 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4465 : std::make_shared<SHADER_MODULE_STATE>();
4466}
4467
sfricke-samsungf91881c2022-03-31 01:12:00 -05004468void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer,
4469 VkDeviceAddress indirectDeviceAddress) {
4470 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004471 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECT2KHR);
sfricke-samsungf91881c2022-03-31 01:12:00 -05004472}
4473
locke-lunargd556cc32019-09-17 01:21:23 -06004474void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4475 const VkAllocationCallbacks *pAllocator,
4476 VkShaderModule *pShaderModule, VkResult result,
4477 void *csm_state_data) {
4478 if (VK_SUCCESS != result) return;
4479 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4480
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004481 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004482}
4483
John Zulauf22b0fbe2019-10-15 06:26:16 -06004484void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4485 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4486 VkResult result) {
4487 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004488 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004489
4490 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4491
4492 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004493 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004494 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004495 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004496
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004497 auto format_features = GetImageFormatFeatures(
4498 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4499 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004500
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004501 auto image_state =
4502 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004503 if (!swapchain_image.fake_base_address) {
4504 auto size = image_state->fragment_encoder->TotalSize();
4505 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004506 }
4507
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004508 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004509 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004510 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004511 }
4512 }
4513
4514 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004515 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4516 }
4517}
sourav parmar35e7a002020-06-09 17:58:44 -07004518
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004519void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4520 const VkCopyAccelerationStructureInfoKHR *pInfo,
4521 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004522 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4523 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004524 if (dst_as_state != nullptr && src_as_state != nullptr) {
4525 dst_as_state->built = true;
4526 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4527 }
4528}
4529
sourav parmar35e7a002020-06-09 17:58:44 -07004530void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4531 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004532 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004533 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004534 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004535 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4536 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004537 if (dst_as_state != nullptr && src_as_state != nullptr) {
4538 dst_as_state->built = true;
4539 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004540 if (!disabled[command_buffer_state]) {
4541 cb_state->AddChild(dst_as_state);
4542 cb_state->AddChild(src_as_state);
4543 }
sourav parmar35e7a002020-06-09 17:58:44 -07004544 }
4545 }
4546}
Piers Daniell39842ee2020-07-10 16:42:33 -06004547
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004548void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4549 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4550 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4551 if (cb_state) {
4552 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4553 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4554 if (!disabled[command_buffer_state]) {
4555 cb_state->AddChild(src_as_state);
4556 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004557 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4558 if (dst_buffer) {
4559 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004560 }
4561 }
4562}
4563
4564void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4565 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4566 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4567 if (cb_state) {
4568 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4569 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004570 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4571 if (buffer_state) {
4572 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004573 }
4574 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4575 cb_state->AddChild(dst_as_state);
4576 }
4577 }
4578}
4579
Piers Daniell39842ee2020-07-10 16:42:33 -06004580void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004581 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004582 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004583}
4584
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004585void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4586 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4587 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4588}
4589
Piers Daniell39842ee2020-07-10 16:42:33 -06004590void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004591 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004592 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004593}
4594
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004595void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4596 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4597 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4598}
4599
Piers Daniell39842ee2020-07-10 16:42:33 -06004600void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4601 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004602 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004603 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004604 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004605}
4606
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004607void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4608 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004609 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004610 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4611 cb_state->primitiveTopology = primitiveTopology;
4612}
4613
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004614void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4615 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004616 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4617 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004618 uint32_t bits = (1u << viewportCount) - 1u;
4619 cb_state->viewportWithCountMask |= bits;
4620 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004621 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004622 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004623
4624 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4625 for (size_t i = 0; i < viewportCount; ++i) {
4626 cb_state->dynamicViewports[i] = pViewports[i];
4627 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004628}
4629
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004630void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4631 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004632 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004633}
4634
4635void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004636 const VkViewport *pViewports) {
4637 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004638}
4639
4640void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4641 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004642 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004643 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004644 uint32_t bits = (1u << scissorCount) - 1u;
4645 cb_state->scissorWithCountMask |= bits;
4646 cb_state->trashedScissorMask &= ~bits;
4647 cb_state->scissorWithCountCount = scissorCount;
4648 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004649}
4650
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004651void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4652 const VkRect2D *pScissors) {
4653 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4654}
4655
4656void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4657 const VkRect2D *pScissors) {
4658 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4659}
4660
4661void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4662 uint32_t bindingCount, const VkBuffer *pBuffers,
4663 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4664 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004665 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004666 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004667
4668 uint32_t end = firstBinding + bindingCount;
4669 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4670 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4671 }
4672
4673 for (uint32_t i = 0; i < bindingCount; ++i) {
4674 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004675 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004676 vertex_buffer_binding.offset = pOffsets[i];
4677 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4678 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4679 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004680 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004681 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004682 }
4683 }
4684}
4685
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004686void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4687 uint32_t bindingCount, const VkBuffer *pBuffers,
4688 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4689 const VkDeviceSize *pStrides) {
4690 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4691 CMD_BINDVERTEXBUFFERS2EXT);
4692}
4693
4694void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4695 uint32_t bindingCount, const VkBuffer *pBuffers,
4696 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4697 const VkDeviceSize *pStrides) {
4698 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4699 CMD_BINDVERTEXBUFFERS2);
4700}
4701
Piers Daniell39842ee2020-07-10 16:42:33 -06004702void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004703 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004704 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004705}
4706
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004707void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4708 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4709 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4710}
4711
Piers Daniell39842ee2020-07-10 16:42:33 -06004712void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004713 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004714 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004715}
4716
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004717void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4718 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4719 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4720}
4721
Piers Daniell39842ee2020-07-10 16:42:33 -06004722void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004723 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004724 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004725}
4726
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004727void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4728 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4729 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4730}
4731
Piers Daniell39842ee2020-07-10 16:42:33 -06004732void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4733 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004734 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004735 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004736}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004737
4738void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4739 VkBool32 depthBoundsTestEnable) {
4740 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4741 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4742}
4743
Piers Daniell39842ee2020-07-10 16:42:33 -06004744void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004745 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004746 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004747}
4748
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004749void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4750 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4751 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4752}
4753
Piers Daniell39842ee2020-07-10 16:42:33 -06004754void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4755 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4756 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004757 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004758 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004759}
locke-lunarg4189aa22020-10-21 00:23:48 -06004760
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004761void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4762 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4763 VkCompareOp compareOp) {
4764 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4765 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4766}
4767
locke-lunarg4189aa22020-10-21 00:23:48 -06004768void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4769 uint32_t discardRectangleCount,
4770 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004771 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004772 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004773}
4774
4775void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4776 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004777 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004778 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004779}
4780
4781void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4782 VkCoarseSampleOrderTypeNV sampleOrderType,
4783 uint32_t customSampleOrderCount,
4784 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004785 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004786 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004787}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004788
4789void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004790 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004791 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004792}
4793
4794void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004795 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004796 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004797}
4798
4799void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4800 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004801 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004802 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004803 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004804}
4805
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004806void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4807 VkBool32 rasterizerDiscardEnable) {
4808 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4809 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004810 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004811}
4812
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004813void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004814 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004815 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004816}
4817
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004818void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4819 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4820 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4821}
4822
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004823void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4824 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004825 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004826 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004827}
Piers Daniell924cd832021-05-18 13:48:47 -06004828
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004829void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4830 VkBool32 primitiveRestartEnable) {
4831 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4832 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4833}
4834
Piers Daniell924cd832021-05-18 13:48:47 -06004835void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4836 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4837 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4838 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004839 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004840 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4841
4842 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4843 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4844 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004845 const auto *dynamic_state = pipeline_state->DynamicState();
4846 if (dynamic_state) {
4847 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4848 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004849 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4850 break;
4851 }
4852 }
4853 }
4854 }
4855 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004856}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004857
ziga-lunarg67b7c392022-03-26 01:45:34 +01004858void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4859 const VkBool32 *pColorWriteEnables) {
4860 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4861 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4862 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4863}
4864
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004865void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004866 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004867 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004868 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004869 // address is used for GPU-AV and ray tracing buffer validation
4870 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004871 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004872 }
4873}
4874
4875void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4876 VkDeviceAddress address) {
4877 RecordGetBufferDeviceAddress(pInfo, address);
4878}
4879
4880void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4881 VkDeviceAddress address) {
4882 RecordGetBufferDeviceAddress(pInfo, address);
4883}
4884
4885void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4886 VkDeviceAddress address) {
4887 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004888}
4889
4890std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4891 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004892 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004893}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004894
4895std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4896 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004897 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004898 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4899}
Rodrigo Locatti37ddb022022-03-15 17:27:42 -03004900
4901std::shared_ptr<DEVICE_MEMORY_STATE> ValidationStateTracker::CreateDeviceMemoryState(
4902 VkDeviceMemory mem, const VkMemoryAllocateInfo *p_alloc_info, uint64_t fake_address, const VkMemoryType &memory_type,
4903 const VkMemoryHeap &memory_heap, layer_data::optional<DedicatedBinding> &&dedicated_binding, uint32_t physical_device_count) {
4904 return std::make_shared<DEVICE_MEMORY_STATE>(mem, p_alloc_info, fake_address, memory_type, memory_heap,
4905 std::move(dedicated_binding), physical_device_count);
4906}