blob: aeb531833a7789cb025505994ae8f28de4a548a6 [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
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300384 VkFormatFeatureFlags2KHR buffer_features, image_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;
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300390 image_features = fmt_props_3.linearTilingFeatures;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200391 } else {
392 VkFormatProperties format_properties;
393 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
394 buffer_features = format_properties.bufferFeatures;
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300395 image_features = format_properties.linearTilingFeatures;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200396 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600397
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300398 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features, image_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600399}
400
401void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
402 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
403 VkResult result) {
404 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600405 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700406
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200407 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600408 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700409 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600410 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700411 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200412 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
413 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
414 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700415 }
416
locke-lunarg9939d4b2020-10-26 20:11:08 -0600417 // 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 -0600418 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600419 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700420 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600421 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700422 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600423 image_format_info.type = image_state->createInfo.imageType;
424 image_format_info.format = image_state->createInfo.format;
425 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600426 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
427 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600428 image_format_info.flags = image_state->createInfo.flags;
429
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600430 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600431
432 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
433 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600434
Jeremy Gebben082a9832021-10-28 13:40:11 -0600435 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600436}
437
438void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
439 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600440 if (disabled[command_buffer_state]) return;
441
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700442 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600443 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600444}
445
Jeff Leger178b1e52020-10-05 12:22:23 -0400446void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600447 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600448 if (disabled[command_buffer_state]) return;
449
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700450 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600451 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
452 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400453}
454
Tony-LunarGef035472021-11-02 10:23:33 -0600455void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
456 if (disabled[command_buffer_state]) return;
457
458 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
459 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
460 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
461}
462
locke-lunargd556cc32019-09-17 01:21:23 -0600463void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
464 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600465 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600466}
467
468void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700469 auto buffer_state = Get<BUFFER_STATE>(buffer);
470 if (buffer_state) {
471 WriteLockGuard guard(buffer_address_lock_);
472 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
473 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600474 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600475}
476
477void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
478 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600479 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600480}
481
482void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
483 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600484 if (disabled[command_buffer_state]) return;
485
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700486 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600487 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600488}
489
490void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
491 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
492 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600493 if (disabled[command_buffer_state]) return;
494
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700495 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600496
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600497 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600498}
499
Jeff Leger178b1e52020-10-05 12:22:23 -0400500void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
501 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600502 if (disabled[command_buffer_state]) return;
503
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700504 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600505 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
506 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400507}
508
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700509void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
510 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
511 if (disabled[command_buffer_state]) return;
512
513 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
514 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
515 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
516}
517
locke-lunargd556cc32019-09-17 01:21:23 -0600518void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
519 VkImageLayout dstImageLayout, uint32_t regionCount,
520 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600521 if (disabled[command_buffer_state]) return;
522
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700523 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600524 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600525}
526
Jeff Leger178b1e52020-10-05 12:22:23 -0400527void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
528 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600529 if (disabled[command_buffer_state]) return;
530
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700531 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600532 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
533 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400534}
535
Tony Barbour845d29b2021-11-09 11:43:14 -0700536void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
537 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
538 if (disabled[command_buffer_state]) return;
539
540 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
541 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
542 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
543}
544
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700545// Gets union of all features defined by Potential Format Features
546// 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 +0200547VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
548 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700549
550 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200551 if (has_format_feature2) {
552 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200553 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
554 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200555 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100556
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200557 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100558
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200559 format_features |= fmt_props_3.linearTilingFeatures;
560 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100561
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200562 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
563 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
564 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
565 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
566 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100567
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200568 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
569 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
570 }
571 }
572 } else {
573 VkFormatProperties format_properties;
574 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
575 format_features |= format_properties.linearTilingFeatures;
576 format_features |= format_properties.optimalTilingFeatures;
577
578 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
579 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
580 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
581
582 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
583
584 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
585 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
586 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
587 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
588
589 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
590 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
591 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700592 }
593 }
594 }
595
596 return format_features;
597}
598
locke-lunargd556cc32019-09-17 01:21:23 -0600599void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
600 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
601 VkResult result) {
602 if (VK_SUCCESS != result) return;
603
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600604 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600605 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
606 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600607 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600608
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600609 device_state->instance_state = this;
610 // Save local link to this device's physical device state
611 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
612 // finish setup in the object representing the device
613 device_state->CreateDevice(pCreateInfo);
614}
615
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -0300616std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags, const VkQueueFamilyProperties &queueFamilyProperties) {
617 return std::make_shared<QUEUE_STATE>(q, index, flags, queueFamilyProperties);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -0600618}
619
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600620void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600621 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
622 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700623 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600624 if (features2) {
625 enabled_features_found = &(features2->features);
626 }
627 }
628
locke-lunargd556cc32019-09-17 01:21:23 -0600629 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600630 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600631 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600632 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600633 }
634
Tony-LunarG273f32f2021-09-28 08:56:30 -0600635 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
636 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600637 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600638 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600639 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600640 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
641 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600642 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600643 }
644
645 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
646 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600647 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
648 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600649 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
650 }
651
652 const auto *pipeline_creation_cache_control_features =
653 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
654 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600655 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600656 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
657 }
658
659 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
660 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600661 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600662 }
663
664 const auto *demote_to_helper_invocation_features =
665 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
666 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600667 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600668 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
669 }
670
671 const auto *terminate_invocation_features =
672 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
673 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600674 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600675 }
676
677 const auto *subgroup_size_control_features =
678 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
679 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600680 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
681 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600682 }
683
684 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
685 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600686 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600687 }
688
689 const auto *texture_compression_astchdr_features =
690 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
691 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600692 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600693 }
694
695 const auto *initialize_workgroup_memory_features =
696 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
697 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600698 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600699 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
700 }
701
702 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
703 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600704 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600705 }
706
707 const auto *shader_integer_dot_product_features =
708 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
709 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600710 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600711 }
712
713 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
714 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600715 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600716 }
717 }
718
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700719 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700720 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600721 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700722 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700723 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.drawIndirectCount = VK_FALSE;
725 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
726 enabled_features.core12.descriptorIndexing = VK_FALSE;
727 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
728 enabled_features.core12.shaderOutputLayer = VK_FALSE;
729 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
730 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700731
732 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700733
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700734 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700735 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
737 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700738 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600739 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700740 }
741
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700742 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700743 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
745 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700746 }
747
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700748 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700749 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600750 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700751 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600752 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700753 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700755 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600756 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700757 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600758 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700759 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700761 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600762 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700763 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600764 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700765 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600768 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700769 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600770 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700771 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600772 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700773 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600774 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700775 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600776 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700777 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600778 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700779 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600780 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700781 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600782 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700783 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600784 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
785 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700786 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600787 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700788 }
789
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700790 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600792 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700793 }
794
795 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700796 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700797 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600798 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700799 }
800
801 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700802 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700803 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600804 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700805 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700806 }
807
808 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700809 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700810 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600811 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700812 }
813
814 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700815 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700816 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600817 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700818 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700819 }
820
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700821 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700822 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600823 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700824 }
825
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700826 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700827 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600828 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700829 }
830
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700831 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700832 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600833 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
834 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
835 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700836 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800837
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700838 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800839 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600840 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
841 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800842 }
843
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700844 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800845 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600846 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
847 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
848 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800849 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
850 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700851 }
852
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700853 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700854 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600855 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700856 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700857 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700858
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700859 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700860 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600861 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
862 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700863 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600864 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
865 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700866 }
867
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700868 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700869 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600870 enabled_features.core11.multiview = multiview_features->multiview;
871 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
872 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700873 }
874
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700875 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700876 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600877 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
878 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700879 }
880
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700881 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700882 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600883 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700884 }
885
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700886 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700887 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600888 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700889 }
890
891 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700892 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700893 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600894 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700895 }
896 }
897
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700898 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600899 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600900 physical_device_count = device_group_ci->physicalDeviceCount;
901 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600902 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600903 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600904 }
locke-lunargd556cc32019-09-17 01:21:23 -0600905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 // Features from other extensions passesd in create info
907 {
908 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
909 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600910 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700911 }
locke-lunargd556cc32019-09-17 01:21:23 -0600912
sfricke-samsung828e59d2021-08-22 23:20:49 -0700913 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
914 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600915 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
919 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600920 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700921 }
locke-lunargd556cc32019-09-17 01:21:23 -0600922
sfricke-samsung828e59d2021-08-22 23:20:49 -0700923 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
924 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600925 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700926 }
locke-lunargd556cc32019-09-17 01:21:23 -0600927
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
929 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600930 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700931 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700932
sfricke-samsung828e59d2021-08-22 23:20:49 -0700933 const auto *buffer_device_address_ext_features =
934 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
935 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600936 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700937 }
locke-lunargd556cc32019-09-17 01:21:23 -0600938
sfricke-samsung828e59d2021-08-22 23:20:49 -0700939 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
940 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600941 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 }
locke-lunargd556cc32019-09-17 01:21:23 -0600943
sfricke-samsung828e59d2021-08-22 23:20:49 -0700944 const auto *compute_shader_derivatives_features =
945 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
946 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600947 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 }
locke-lunargd556cc32019-09-17 01:21:23 -0600949
sfricke-samsung828e59d2021-08-22 23:20:49 -0700950 const auto *fragment_shader_barycentric_features =
951 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
952 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600953 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700954 }
locke-lunargd556cc32019-09-17 01:21:23 -0600955
sfricke-samsung828e59d2021-08-22 23:20:49 -0700956 const auto *shader_image_footprint_features =
957 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
958 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600959 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700960 }
locke-lunargd556cc32019-09-17 01:21:23 -0600961
sfricke-samsung828e59d2021-08-22 23:20:49 -0700962 const auto *fragment_shader_interlock_features =
963 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
964 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600965 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 }
locke-lunargd556cc32019-09-17 01:21:23 -0600967
sfricke-samsung828e59d2021-08-22 23:20:49 -0700968 const auto *texel_buffer_alignment_features =
969 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
970 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600971 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 }
locke-lunargd556cc32019-09-17 01:21:23 -0600973
sfricke-samsung828e59d2021-08-22 23:20:49 -0700974 const auto *pipeline_exe_props_features =
975 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
976 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600977 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 }
locke-lunargd556cc32019-09-17 01:21:23 -0600979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *dedicated_allocation_image_aliasing_features =
981 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
982 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600983 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700984 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500985
sfricke-samsung828e59d2021-08-22 23:20:49 -0700986 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
987 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600988 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
992 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600993 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700994 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000995
sfricke-samsung828e59d2021-08-22 23:20:49 -0700996 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
997 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600998 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 }
sfricke-samsungcead0802020-01-30 22:20:10 -08001000
sfricke-samsung828e59d2021-08-22 23:20:49 -07001001 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
1002 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001003 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001004 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001005
sfricke-samsung828e59d2021-08-22 23:20:49 -07001006 const auto *ray_tracing_pipeline_features =
1007 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
1008 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001009 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001010 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001011
sfricke-samsung828e59d2021-08-22 23:20:49 -07001012 const auto *ray_tracing_acceleration_structure_features =
1013 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
1014 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001015 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001016 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001017
sfricke-samsung828e59d2021-08-22 23:20:49 -07001018 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
1019 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001020 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 }
Jeff Bolz165818a2020-05-08 11:19:03 -05001022
sfricke-samsung828e59d2021-08-22 23:20:49 -07001023 const auto *fragment_density_map_features =
1024 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1025 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001026 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001028
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 const auto *fragment_density_map_features2 =
1030 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1031 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001032 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001034
Agarwal, Arpit78509112022-02-17 15:29:05 -07001035 const auto *fragment_density_map_offset_features =
1036 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1037 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001038 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001039 }
1040
sfricke-samsung828e59d2021-08-22 23:20:49 -07001041 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1042 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001043 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001044 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001045
sfricke-samsung828e59d2021-08-22 23:20:49 -07001046 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1047 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001048 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001050
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 const auto *fragment_shading_rate_features =
1052 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1053 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001054 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001055 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001056
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001057 const auto *fragment_shading_rate_enums_features =
1058 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1059 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001060 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001061 }
1062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *extended_dynamic_state_features =
1064 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1065 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001066 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001068
sfricke-samsung828e59d2021-08-22 23:20:49 -07001069 const auto *extended_dynamic_state2_features =
1070 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1071 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001072 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001073 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001074
sfricke-samsung828e59d2021-08-22 23:20:49 -07001075 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1076 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001077 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1081 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001082 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001083 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001084
sfricke-samsung828e59d2021-08-22 23:20:49 -07001085 const auto *shader_integer_functions2_features =
1086 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1087 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001088 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001089 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001090
sfricke-samsung828e59d2021-08-22 23:20:49 -07001091 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1092 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001093 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001094 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001095
sfricke-samsung828e59d2021-08-22 23:20:49 -07001096 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1097 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001098 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001100
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 const auto *shader_image_atomic_int64_features =
1102 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1103 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001104 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001106
sfricke-samsung828e59d2021-08-22 23:20:49 -07001107 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1108 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001109 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001111
sfricke-samsung828e59d2021-08-22 23:20:49 -07001112 const auto *conditional_rendering_features =
1113 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1114 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001115 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001116 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001117
sfricke-samsung828e59d2021-08-22 23:20:49 -07001118 const auto *workgroup_memory_explicit_layout_features =
1119 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1120 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001121 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001122 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001123
sfricke-samsung828e59d2021-08-22 23:20:49 -07001124 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1125 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001126 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 }
Locke Linf3873542021-04-26 11:25:10 -06001128
sfricke-samsung828e59d2021-08-22 23:20:49 -07001129 const auto *vertex_input_dynamic_state_features =
1130 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1131 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001132 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001133 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001134
sfricke-samsung828e59d2021-08-22 23:20:49 -07001135 const auto *inherited_viewport_scissor_features =
1136 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1137 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001138 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001139 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001140
sfricke-samsung828e59d2021-08-22 23:20:49 -07001141 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1142 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001143 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001144 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001145
sfricke-samsung828e59d2021-08-22 23:20:49 -07001146 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1147 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001148 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001149 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001150
sfricke-samsung828e59d2021-08-22 23:20:49 -07001151 const auto *shader_atomic_float2_features =
1152 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1153 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001154 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001155 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001156
sfricke-samsung828e59d2021-08-22 23:20:49 -07001157 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1158 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001159 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001160 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001161
sfricke-samsung828e59d2021-08-22 23:20:49 -07001162 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1163 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001164 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001165 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001166
1167 const auto *ray_tracing_motion_blur_features =
1168 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1169 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001170 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001171 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001172
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001173 const auto *primitive_topology_list_restart_features =
1174 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1175 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001176 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001177 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001178
ziga-lunarge1988962021-09-16 13:32:34 +02001179 const auto *zero_initialize_work_group_memory_features =
1180 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1181 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001182 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001183 }
1184
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001185 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1186 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001187 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001188 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001189
Tony-LunarG69604c42021-11-22 16:00:12 -07001190 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1191 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001192 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001193 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001194
1195 const auto *primitives_generated_query_features =
1196 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1197 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001198 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001199 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001200
1201 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1202 if (image_2d_view_of_3d_features) {
1203 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1204 }
Nathaniel Cesario553ab032022-04-14 10:56:22 -06001205
1206 const auto graphics_pipeline_library_features =
1207 LvlFindInChain<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(pCreateInfo->pNext);
1208 if (graphics_pipeline_library_features) {
1209 enabled_features.graphics_pipeline_library_features = *graphics_pipeline_library_features;
1210 }
ziga-lunarge25f5f02022-04-16 15:07:35 +02001211
1212 const auto shader_subgroup_uniform_control_flow_features =
1213 LvlFindInChain<VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR>(pCreateInfo->pNext);
1214 if (shader_subgroup_uniform_control_flow_features) {
1215 enabled_features.shader_subgroup_uniform_control_flow_features = *shader_subgroup_uniform_control_flow_features;
1216 }
Mike Schuchardt840f1252022-05-11 11:31:25 -07001217
sjfrickee9b39372022-05-22 13:02:17 +09001218 const auto ray_tracing_maintenance1_features =
Mike Schuchardt840f1252022-05-11 11:31:25 -07001219 LvlFindInChain<VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR>(pCreateInfo->pNext);
1220 if (ray_tracing_maintenance1_features) {
1221 enabled_features.ray_tracing_maintenance1_features= *ray_tracing_maintenance1_features;
1222 }
sjfricke52defd42022-08-08 16:37:46 +09001223
Tony-LunarG206b1bb2022-06-13 12:20:05 -06001224 const auto non_seamless_cube_map_features =
1225 LvlFindInChain<VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT>(pCreateInfo->pNext);
1226 if (non_seamless_cube_map_features) {
1227 enabled_features.non_seamless_cube_map_features = *non_seamless_cube_map_features;
1228 }
Tony-LunarG7384f7e2022-07-05 14:20:42 -06001229
1230 const auto multisampled_render_to_single_sampled_features =
1231 LvlFindInChain<VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT>(pCreateInfo->pNext);
1232 if (multisampled_render_to_single_sampled_features) {
1233 enabled_features.multisampled_render_to_single_sampled_features = *multisampled_render_to_single_sampled_features;
1234 }
Tony-LunarG1672d002022-08-03 14:35:34 -06001235
1236 const auto shader_module_identifier_features =
1237 LvlFindInChain<VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT>(pCreateInfo->pNext);
1238 if (shader_module_identifier_features) {
1239 enabled_features.shader_module_identifier_features = *shader_module_identifier_features;
1240 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001241 }
1242
locke-lunargd556cc32019-09-17 01:21:23 -06001243 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001244 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1245 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001246
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001247 {
1248 uint32_t n_props = 0;
1249 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001250 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001251 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001252 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001253
1254 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001255 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001256 }
1257
1258 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1259 // a path to grab that information from the physical device. This
1260 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1261 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001262 has_format_feature2 =
1263 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1264 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001265 }
1266
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001267 const auto &dev_ext = device_extensions;
1268 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001269
Tony-LunarG273f32f2021-09-28 08:56:30 -06001270 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1271 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001272 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1273 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001274 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001275 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001276 } else {
1277 // VkPhysicalDeviceVulkan11Properties
1278 //
1279 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1280
1281 if (dev_ext.vk_khr_multiview) {
1282 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001283 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1284 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1285 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001286 }
1287
1288 if (dev_ext.vk_khr_maintenance3) {
1289 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001290 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1291 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1292 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001293 }
1294
1295 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001296 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001297 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1298 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1299 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001300 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001301
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001302 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1303 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1304 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1305 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001307 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001308 }
1309
1310 // VkPhysicalDeviceVulkan12Properties
1311 //
1312 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1313
1314 if (dev_ext.vk_ext_descriptor_indexing) {
1315 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001316 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1317 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001318 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001319 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001320 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001321 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001322 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001323 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001324 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001325 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001326 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001327 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001328 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001329 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1330 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1331 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001332 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001333 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001334 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001335 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001336 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001337 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001338 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001339 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001340 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001341 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001342 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001343 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001344 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001345 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001346 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001347 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001348 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001349 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001350 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001351 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001352 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001353 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001354 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001355 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001356 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001357 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001358 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001359 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001360 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1361 }
1362
1363 if (dev_ext.vk_khr_depth_stencil_resolve) {
1364 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001365 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1366 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1367 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1368 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1369 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001370 }
1371
1372 if (dev_ext.vk_khr_timeline_semaphore) {
1373 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001374 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1375 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001376 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1377 }
1378
1379 if (dev_ext.vk_ext_sampler_filter_minmax) {
1380 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001381 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1382 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001383 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001384 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001385 }
1386
1387 if (dev_ext.vk_khr_shader_float_controls) {
1388 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001389 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1390 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1391 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1392 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001393 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001394 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001395 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001396 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001397 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001398 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1399 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1400 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1401 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1402 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1403 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1404 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1405 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1406 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1407 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1408 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1409 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001410 }
locke-lunargd556cc32019-09-17 01:21:23 -06001411 }
1412
sfricke-samsung828e59d2021-08-22 23:20:49 -07001413 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001414 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1415 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1416 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1417 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1418 &phys_dev_props->inline_uniform_block_props);
1419 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1420 &phys_dev_props->vtx_attrib_divisor_props);
1421 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1422 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1423 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1424 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1425 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1426 &phys_dev_props->texel_buffer_alignment_props);
1427 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1428 &phys_dev_props->fragment_density_map_props);
1429 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1430 &phys_dev_props->fragment_density_map2_props);
1431 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001432 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001433 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1434 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1435 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1436 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1437 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1438 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1439 &phys_dev_props->fragment_shading_rate_props);
1440 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1441 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1442 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1443 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1444 &phys_dev_props->blend_operation_advanced_props);
1445 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1446 &phys_dev_props->conservative_rasterization_props);
1447 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1448 &phys_dev_props->subgroup_size_control_props);
ziga-lunarge25f5f02022-04-16 15:07:35 +02001449 if (api_version >= VK_API_VERSION_1_1) {
1450 GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_properties);
1451 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001452
sfricke-samsung45996a42021-09-16 13:45:27 -07001453 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001454 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001455 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1456 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001457 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1458 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001459
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001460 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001461 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1462 NULL);
1463 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001464
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001465 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1466 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001467 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001468
locke-lunargd556cc32019-09-17 01:21:23 -06001469 // Store queue family data
1470 if (pCreateInfo->pQueueCreateInfos != nullptr) {
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001471 uint32_t num_queue_families = 0;
1472 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
1473 std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
1474 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
1475
locke-lunargd556cc32019-09-17 01:21:23 -06001476 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001477 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001478 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1479 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001480 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001481 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001482 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001483 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1484 VkQueue queue = VK_NULL_HANDLE;
1485 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1486 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1487 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1488 get_info.flags = queue_info.flags;
1489 get_info.queueFamilyIndex = queue_info.queue_family_index;
1490 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001491 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001492 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001493 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001494 }
1495 assert(queue != VK_NULL_HANDLE);
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001496 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags,
1497 queue_family_properties_list[queue_info.queue_family_index]));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001498 }
locke-lunargd556cc32019-09-17 01:21:23 -06001499 }
1500 }
1501}
1502
1503void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1504 if (!device) return;
1505
Jeremy Gebbend177d922021-10-28 13:42:10 -06001506 command_pool_map_.clear();
1507 assert(command_buffer_map_.empty());
1508 pipeline_map_.clear();
1509 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001510
1511 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001512 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001513 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001514 assert(descriptor_set_map_.empty());
1515 desc_template_map_.clear();
1516 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001517 // Because swapchains are associated with Surfaces, which are at instance level,
1518 // they need to be explicitly destroyed here to avoid continued references to
1519 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001520 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001521 entry.second->Destroy();
1522 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001523 swapchain_map_.clear();
1524 image_view_map_.clear();
1525 image_map_.clear();
1526 buffer_view_map_.clear();
1527 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001528 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001529 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001530}
1531
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001532void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1533 VkFence fence, VkResult result) {
1534 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001535 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001536
Jeremy Gebben57642982021-09-14 14:14:55 -06001537 uint64_t early_retire_seq = 0;
1538
1539 if (submitCount == 0) {
1540 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001541 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001542 early_retire_seq = queue_state->Submit(std::move(submission));
1543 }
locke-lunargd556cc32019-09-17 01:21:23 -06001544
1545 // Now process each individual submit
1546 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001547 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001548 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001549 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001550 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001551 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001552 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1553 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1554 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1555 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001556 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001557 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001558
locke-lunargd556cc32019-09-17 01:21:23 -06001559 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001560 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001561 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1562 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1563 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1564 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001565 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001566 }
1567
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001568 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001569 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001570
locke-lunargd556cc32019-09-17 01:21:23 -06001571 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001572 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1573 if (cb_state) {
1574 submission.AddCommandBuffer(std::move(cb_state));
1575 }
locke-lunargd556cc32019-09-17 01:21:23 -06001576 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001577 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001578 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001579 }
1580 auto submit_seq = queue_state->Submit(std::move(submission));
1581 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001582 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001583
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001584 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001585 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001586 }
1587}
1588
Tony-LunarG26fe2842021-11-16 14:07:59 -07001589void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1590 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001591 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001592 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001593 uint64_t early_retire_seq = 0;
1594 if (submitCount == 0) {
1595 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001596 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001597 early_retire_seq = queue_state->Submit(std::move(submission));
1598 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001599
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001600 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1601 CB_SUBMISSION submission;
1602 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001603 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1604 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001605 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001606 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001607 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1608 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001609 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001610 }
1611 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1612 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1613
1614 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001615 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001616 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001617 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001618 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001619 }
1620 auto submit_seq = queue_state->Submit(std::move(submission));
1621 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001622 }
locke-lunargd556cc32019-09-17 01:21:23 -06001623 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001624 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001625 }
1626}
1627
Tony-LunarG26fe2842021-11-16 14:07:59 -07001628void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1629 VkFence fence, VkResult result) {
1630 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1631}
1632
1633void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1634 VkFence fence, VkResult result) {
1635 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1636}
1637
locke-lunargd556cc32019-09-17 01:21:23 -06001638void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1639 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1640 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001641 if (VK_SUCCESS != result) {
1642 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001643 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001644 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1645 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1646 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1647
1648 layer_data::optional<DedicatedBinding> dedicated_binding;
1649
1650 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1651 if (dedicated) {
1652 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001653 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001654 assert(buffer_state);
1655 if (!buffer_state) {
1656 return;
1657 }
1658 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1659 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001660 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001661 assert(image_state);
1662 if (!image_state) {
1663 return;
1664 }
1665 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1666 }
1667 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001668 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1669 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001670 return;
1671}
1672
1673void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001674 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001675 if (mem_info) {
1676 fake_memory.Free(mem_info->fake_base_address);
1677 }
1678 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001679}
1680
1681void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1682 VkFence fence, VkResult result) {
1683 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001684 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001685
Jeremy Gebben57642982021-09-14 14:14:55 -06001686 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001687
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001688 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1689 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001690 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001691 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1692 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1693 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001694 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001695 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001696 if (buffer_state) {
1697 buffer_state->BindMemory(buffer_state.get(), mem_state, sparse_binding.memoryOffset,
1698 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001699 }
locke-lunargd556cc32019-09-17 01:21:23 -06001700 }
1701 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001702 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1703 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1704 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001705 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001706 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001707 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001708 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1709 // See: VUID-vkGetImageSubresourceLayout-image-01895
1710 if (!image_state->fragment_encoder) {
1711 image_state->fragment_encoder =
1712 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1713 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001714 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset,
1715 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001716 }
locke-lunargd556cc32019-09-17 01:21:23 -06001717 }
1718 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001719 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1720 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1721 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001722 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1723 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Aitor Camacho3294edd2022-05-16 22:34:19 +02001724 VkDeviceSize offset = sparse_binding.offset.z * sparse_binding.offset.y * sparse_binding.offset.x * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001725 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001726 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001727 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001728 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1729 // See: VUID-vkGetImageSubresourceLayout-image-01895
1730 if (!image_state->fragment_encoder) {
1731 image_state->fragment_encoder =
1732 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1733 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001734 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset, offset, size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001735 }
locke-lunargd556cc32019-09-17 01:21:23 -06001736 }
1737 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001738 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001739 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001740 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001741 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001742 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001743 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001744 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001745 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001746 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001747 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001748 auto submit_seq = queue_state->Submit(std::move(submission));
1749 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001750 }
1751
1752 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001753 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001754 }
1755}
1756
1757void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1758 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1759 VkResult result) {
1760 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06001761 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext), pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001762}
1763
Mike Schuchardt2df08912020-12-15 16:28:09 -08001764void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1765 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001766 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1767 if (semaphore_state) {
1768 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001769 }
1770}
1771
Mike Schuchardt2df08912020-12-15 16:28:09 -08001772void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001773 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001774 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001775 if (semaphore_state) {
1776 semaphore_state->RetireTimeline(pSignalInfo->value);
1777 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001778}
1779
locke-lunargd556cc32019-09-17 01:21:23 -06001780void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001781 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001782 if (mem_info) {
1783 mem_info->mapped_range.offset = offset;
1784 mem_info->mapped_range.size = size;
1785 mem_info->p_driver_data = *ppData;
1786 }
1787}
1788
locke-lunargd556cc32019-09-17 01:21:23 -06001789void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1790 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1791 if (VK_SUCCESS != result) return;
1792
1793 // When we know that all fences are complete we can clean/remove their CBs
1794 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1795 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001796 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001797 if (fence_state) {
1798 fence_state->Retire();
1799 }
locke-lunargd556cc32019-09-17 01:21:23 -06001800 }
1801 }
1802 // NOTE : Alternate case not handled here is when some fences have completed. In
1803 // this case for app to guarantee which fences completed it will have to call
1804 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1805}
1806
John Zulauff89de662020-04-13 18:57:34 -06001807void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1808 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001809 if (VK_SUCCESS != result) return;
1810
Jeremy Gebben15332642021-12-15 19:33:15 -07001811 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1812 // the application calls vkGetSemaphoreCounterValue() on each of them.
1813 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1814 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1815 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1816 if (semaphore_state) {
1817 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1818 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001819 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001820 }
1821}
1822
John Zulauff89de662020-04-13 18:57:34 -06001823void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1824 VkResult result) {
1825 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1826}
1827
1828void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1829 uint64_t timeout, VkResult result) {
1830 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1831}
1832
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001833void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1834 VkResult result) {
1835 if (VK_SUCCESS != result) return;
1836
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001837 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001838 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001839 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001840 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001841}
1842
1843void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1844 VkResult result) {
1845 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1846}
1847void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1848 VkResult result) {
1849 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1850}
1851
locke-lunargd556cc32019-09-17 01:21:23 -06001852void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1853 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001854 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001855 if (fence_state) {
1856 fence_state->Retire();
1857 }
locke-lunargd556cc32019-09-17 01:21:23 -06001858}
1859
Yilong Lice03a312022-01-02 02:08:35 -08001860void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1861 if (Get<QUEUE_STATE>(queue) == nullptr) {
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001862 uint32_t num_queue_families = 0;
1863 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
1864 std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
1865 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
1866
1867 Add(CreateQueue(queue, queue_family_index, flags, queue_family_properties_list[queue_family_index]));
Yilong Lice03a312022-01-02 02:08:35 -08001868 }
1869}
1870
1871void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1872 VkQueue *pQueue) {
1873 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1874}
1875
1876void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1877 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1878}
1879
locke-lunargd556cc32019-09-17 01:21:23 -06001880void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1881 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001882 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001883 if (queue_state) {
1884 queue_state->Retire();
1885 }
locke-lunargd556cc32019-09-17 01:21:23 -06001886}
1887
1888void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1889 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001890 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001891 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001892 }
1893}
1894
1895void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001896 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001897}
1898
1899void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1900 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001901 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001902}
1903
1904void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001905 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001906}
1907
1908void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1909 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001910 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001911}
1912
locke-lunargd556cc32019-09-17 01:21:23 -06001913void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001914 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001915 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001916 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001917 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001918 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02001919 buffer_state->BindMemory(buffer_state.get(), mem_state, memoryOffset, 0u, buffer_state->requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001920 }
locke-lunargd556cc32019-09-17 01:21:23 -06001921 }
1922}
1923
1924void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1925 VkDeviceSize memoryOffset, VkResult result) {
1926 if (VK_SUCCESS != result) return;
1927 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1928}
1929
1930void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001931 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001932 for (uint32_t i = 0; i < bindInfoCount; i++) {
1933 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1934 }
1935}
1936
1937void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001938 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001939 for (uint32_t i = 0; i < bindInfoCount; i++) {
1940 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1941 }
1942}
1943
Spencer Fricke6c127102020-04-16 06:25:20 -07001944void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001945 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001946 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001947 buffer_state->memory_requirements_checked = true;
1948 }
1949}
1950
1951void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1952 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001953 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001954}
1955
1956void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001957 const VkBufferMemoryRequirementsInfo2 *pInfo,
1958 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001959 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001960}
1961
1962void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001963 const VkBufferMemoryRequirementsInfo2 *pInfo,
1964 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001965 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001966}
1967
Spencer Fricke6c127102020-04-16 06:25:20 -07001968void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001969 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001970 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001971 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001972 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001973 if (plane_info != nullptr) {
1974 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001975 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001976 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001977 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001978 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001979 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001980 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001981 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001982 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001983 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001984 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001985 }
locke-lunargd556cc32019-09-17 01:21:23 -06001986 }
1987}
1988
1989void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1990 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001991 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001992}
1993
1994void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1995 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001996 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001997}
1998
1999void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
2000 const VkImageMemoryRequirementsInfo2 *pInfo,
2001 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002002 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002003}
2004
locke-lunargd556cc32019-09-17 01:21:23 -06002005void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
2006 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
2007 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002008 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06002009 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002010}
2011
2012void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002013 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2014 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002015 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002016 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002017}
2018
2019void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002020 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2021 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002022 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002023 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002024}
2025
2026void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2027 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002028 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06002029}
2030
2031void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2032 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002033 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002034}
2035
2036void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2037 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2042 const VkAllocationCallbacks *pAllocator) {
2043 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002044 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002045 // Any bound cmd buffers are now invalid
2046 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002047 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2048 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2049 custom_border_color_sampler_count--;
2050 }
locke-lunargd556cc32019-09-17 01:21:23 -06002051 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06002052 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002053}
2054
2055void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2056 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002057 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002058}
2059
2060void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2061 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002062 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002063}
2064
locke-lunargd556cc32019-09-17 01:21:23 -06002065void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2066 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002067 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2068 if (pool) {
2069 pool->Free(commandBufferCount, pCommandBuffers);
2070 }
locke-lunargd556cc32019-09-17 01:21:23 -06002071}
2072
2073void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2074 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2075 VkResult result) {
2076 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002077 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002078 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06002079}
2080
2081void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2082 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2083 VkResult result) {
2084 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002085
2086 uint32_t index_count = 0, n_perf_pass = 0;
2087 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002088 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002089 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002090 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002091
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002092 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002093 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2094 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2095 switch (counter.scope) {
2096 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002097 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002098 break;
2099 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002100 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002101 break;
2102 default:
2103 break;
2104 }
2105 }
2106
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002107 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002108 }
2109
Jeremy Gebben082a9832021-10-28 13:40:11 -06002110 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 -06002111
locke-lunargd556cc32019-09-17 01:21:23 -06002112}
2113
2114void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2115 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002116 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002117}
2118
2119void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2120 VkCommandPoolResetFlags flags, VkResult result) {
2121 if (VK_SUCCESS != result) return;
2122 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002123 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2124 if (pool) {
2125 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002126 }
2127}
2128
2129void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2130 VkResult result) {
2131 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002132 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002133 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002134 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002135 }
2136 }
2137}
2138
locke-lunargd556cc32019-09-17 01:21:23 -06002139void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2140 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002141 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002142}
2143
2144void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2145 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002146 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002147}
2148
2149void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2150 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2151 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002152 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002153}
2154
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002155std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2156 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2157 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2158 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2159}
2160
locke-lunargd556cc32019-09-17 01:21:23 -06002161bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2162 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2163 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002164 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002165 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002166 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2167 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2168 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2169 cgpl_state->pipe_state.reserve(count);
2170 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002171 const auto &create_info = pCreateInfos[i];
2172 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2173 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2174
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002175 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002176 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002177 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002178 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2179 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002180 } else {
2181 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2182 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2183 if (!is_graphics_lib && !has_link_info) {
2184 skip = true;
2185 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002186 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002187 cgpl_state->pipe_state.push_back(
2188 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002189 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002190 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002191}
2192
2193void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2194 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2195 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2196 VkResult result, void *cgpl_state_data) {
2197 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2198 // This API may create pipelines regardless of the return value
2199 for (uint32_t i = 0; i < count; i++) {
2200 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002201 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002202 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002203 }
2204 }
2205 cgpl_state->pipe_state.clear();
2206}
2207
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002208std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2209 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2210 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2211}
2212
locke-lunargd556cc32019-09-17 01:21:23 -06002213bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2214 const VkComputePipelineCreateInfo *pCreateInfos,
2215 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002216 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002217 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2218 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2219 ccpl_state->pipe_state.reserve(count);
2220 for (uint32_t i = 0; i < count; i++) {
2221 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002222 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002223 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002224 }
2225 return false;
2226}
2227
2228void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2229 const VkComputePipelineCreateInfo *pCreateInfos,
2230 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2231 VkResult result, void *ccpl_state_data) {
2232 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2233
2234 // This API may create pipelines regardless of the return value
2235 for (uint32_t i = 0; i < count; i++) {
2236 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002237 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002238 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002239 }
2240 }
2241 ccpl_state->pipe_state.clear();
2242}
2243
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002244std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2245 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2246 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2247}
2248
locke-lunargd556cc32019-09-17 01:21:23 -06002249bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2250 uint32_t count,
2251 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2252 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002253 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002254 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2255 crtpl_state->pipe_state.reserve(count);
2256 for (uint32_t i = 0; i < count; i++) {
2257 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002258 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002259 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002260 }
2261 return false;
2262}
2263
2264void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2265 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2266 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2267 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2268 // This API may create pipelines regardless of the return value
2269 for (uint32_t i = 0; i < count; i++) {
2270 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002271 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002272 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002273 }
2274 }
2275 crtpl_state->pipe_state.clear();
2276}
2277
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002278std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2279 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2280 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2281}
2282
sourav parmarcd5fb182020-07-17 12:58:44 -07002283bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2284 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002285 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2286 const VkAllocationCallbacks *pAllocator,
2287 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002288 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002289 crtpl_state->pipe_state.reserve(count);
2290 for (uint32_t i = 0; i < count; i++) {
2291 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002292 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002293 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002294 }
2295 return false;
2296}
2297
sourav parmarcd5fb182020-07-17 12:58:44 -07002298void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2299 VkPipelineCache pipelineCache, uint32_t count,
2300 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2301 const VkAllocationCallbacks *pAllocator,
2302 VkPipeline *pPipelines, VkResult result,
2303 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002304 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002305 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002306 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002307
2308 if (!operation_is_deferred) {
2309 for (uint32_t i = 0; i < count; i++) {
2310 if (pPipelines[i] != VK_NULL_HANDLE) {
2311 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2312 Add(std::move((crtpl_state->pipe_state)[i]));
2313 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002314 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002315 } else {
2316 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2317 if (wrap_handles) {
2318 deferredOperation = layer_data->Unwrap(deferredOperation);
2319 }
2320 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2321 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2322 if (find_res->first) {
2323 cleanup_fn = std::move(find_res->second);
2324 }
2325 auto &pipeline_states = crtpl_state->pipe_state;
2326 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2327 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2328 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2329 pipeline_states[i]->SetHandle(pipelines[i]);
2330 this->Add(std::move(pipeline_states[i]));
2331 }
2332 });
2333 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002334 }
2335 crtpl_state->pipe_state.clear();
2336}
2337
locke-lunargd556cc32019-09-17 01:21:23 -06002338void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2339 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2340 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002341 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002342 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2343 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002344 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002345 }
locke-lunargd556cc32019-09-17 01:21:23 -06002346}
2347
2348void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2349 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2350 const VkAllocationCallbacks *pAllocator,
2351 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2352 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002353 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002354}
2355
locke-lunargd556cc32019-09-17 01:21:23 -06002356void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2357 const VkAllocationCallbacks *pAllocator,
2358 VkPipelineLayout *pPipelineLayout, VkResult result) {
2359 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002360 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002361}
2362
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002363std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2364 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2365 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2366}
2367
locke-lunargd556cc32019-09-17 01:21:23 -06002368void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2369 const VkAllocationCallbacks *pAllocator,
2370 VkDescriptorPool *pDescriptorPool, VkResult result) {
2371 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002372 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002373}
2374
2375void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2376 VkDescriptorPoolResetFlags flags, VkResult result) {
2377 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002378 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2379 if (pool) {
2380 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002381 }
locke-lunargd556cc32019-09-17 01:21:23 -06002382}
2383
2384bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2385 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002386 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002387 // Always update common data
2388 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2389 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2390 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2391
2392 return false;
2393}
2394
2395// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2396void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2397 VkDescriptorSet *pDescriptorSets, VkResult result,
2398 void *ads_state_data) {
2399 if (VK_SUCCESS != result) return;
2400 // All the updates are contained in a single cvdescriptorset function
2401 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2402 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002403 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2404 if (pool_state) {
2405 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2406 }
locke-lunargd556cc32019-09-17 01:21:23 -06002407}
2408
2409void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2410 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002411 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2412 if (pool_state) {
2413 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002414 }
2415}
2416
2417void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2418 const VkWriteDescriptorSet *pDescriptorWrites,
2419 uint32_t descriptorCopyCount,
2420 const VkCopyDescriptorSet *pDescriptorCopies) {
2421 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2422 pDescriptorCopies);
2423}
2424
2425void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002426 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002427 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002428 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002429 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002430 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002431 }
2432}
2433
locke-lunargd556cc32019-09-17 01:21:23 -06002434void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2435 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002436 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002437 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002438
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002439 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002440}
2441
2442void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002443 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002444 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002445
2446 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002447}
2448
2449void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2450 VkResult result) {
2451 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002452 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2453 if (cb_state) {
2454 cb_state->Reset();
2455 }
locke-lunargd556cc32019-09-17 01:21:23 -06002456 }
2457}
2458
2459CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2460 // initially assume everything is static state
2461 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2462
2463 if (ds) {
2464 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002465 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002466 }
2467 }
locke-lunargd556cc32019-09-17 01:21:23 -06002468 return flags;
2469}
2470
2471// Validation cache:
2472// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002473
2474void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2475 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002476 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002477 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002478 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002479
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002480 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002481 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002482 const auto *raster_state = pipe_state->RasterizationState();
2483 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002484 const auto *viewport_state = pipe_state->ViewportState();
2485 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002486 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002487 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002488 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002489 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002490
2491 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002492 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2493 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002494 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002495 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002496 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002497 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002498 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002499 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002500
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002501 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002502 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2503 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2504 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002505 if (!has_dynamic_viewport_count) {
2506 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002507 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002508 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2509 // should become = ~uint32_t(0) if the other interpretation is correct.
2510 }
2511 }
2512 if (!has_dynamic_scissor_count) {
2513 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002514 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002515 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2516 // should become = ~uint32_t(0) if the other interpretation is correct.
2517 }
2518 }
locke-lunargd556cc32019-09-17 01:21:23 -06002519 }
Nathaniel Cesario62f03592022-07-11 09:19:20 -06002520 cb_state->BindPipeline(ConvertToLvlBindPoint(pipelineBindPoint), pipe_state.get());
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002521 if (!disabled[command_buffer_state]) {
2522 cb_state->AddChild(pipe_state);
2523 }
locke-lunargd556cc32019-09-17 01:21:23 -06002524}
2525
2526void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2527 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002528 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002529 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002530 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2531 cb_state->viewportMask |= bits;
2532 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002533
2534 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2535 for (size_t i = 0; i < viewportCount; ++i) {
2536 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2537 }
locke-lunargd556cc32019-09-17 01:21:23 -06002538}
2539
2540void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2541 uint32_t exclusiveScissorCount,
2542 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002543 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002544 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002545 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2546 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002547}
2548
2549void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2550 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002551 if (disabled[command_buffer_state]) return;
2552
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002553 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002554 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002555
2556 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002557 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002558 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002559 }
2560}
2561
2562void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2563 uint32_t viewportCount,
2564 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002565 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002566 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002567 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2568 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002569}
2570
2571void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2572 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2573 const VkAllocationCallbacks *pAllocator,
2574 VkAccelerationStructureNV *pAccelerationStructure,
2575 VkResult result) {
2576 if (VK_SUCCESS != result) return;
Aitor Camacho3294edd2022-05-16 22:34:19 +02002577 std::shared_ptr<ACCELERATION_STRUCTURE_STATE> state =
2578 std::make_shared<ACCELERATION_STRUCTURE_STATE_LINEAR>(device, *pAccelerationStructure, pCreateInfo);
2579 Add(std::move(state));
locke-lunargd556cc32019-09-17 01:21:23 -06002580}
2581
Jeff Bolz95176d02020-04-01 00:36:16 -05002582void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2583 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2584 const VkAllocationCallbacks *pAllocator,
2585 VkAccelerationStructureKHR *pAccelerationStructure,
2586 VkResult result) {
2587 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002588 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2589 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002590}
2591
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002592void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2593 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2594 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2595 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2596 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002597 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002598 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002599 dst_as_state->Build(&pInfos[i], true, *ppBuildRangeInfos);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002600 }
2601 }
2602}
2603
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002604// helper method for device side acceleration structure builds
2605void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2606 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2607 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2608 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002609 dst_as_state->Build(&info, false, nullptr);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002610 }
2611 if (disabled[command_buffer_state]) {
2612 return;
2613 }
2614 if (dst_as_state) {
2615 cb_state.AddChild(dst_as_state);
2616 }
2617 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2618 if (src_as_state) {
2619 cb_state.AddChild(src_as_state);
2620 }
2621 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2622 if (scratch_buffer) {
2623 cb_state.AddChild(scratch_buffer);
2624 }
2625
2626 for (uint32_t i = 0; i < info.geometryCount; i++) {
2627 // only one of pGeometries and ppGeometries can be non-null
2628 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2629 switch (geom.geometryType) {
2630 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2631 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2632 if (vertex_buffer) {
2633 cb_state.AddChild(vertex_buffer);
2634 }
2635 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2636 if (index_buffer) {
2637 cb_state.AddChild(index_buffer);
2638 }
2639 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2640 if (transform_buffer) {
2641 cb_state.AddChild(transform_buffer);
2642 }
2643 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2644 if (motion_data) {
2645 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2646 if (motion_buffer) {
2647 cb_state.AddChild(motion_buffer);
2648 }
2649 }
2650 } break;
2651 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2652 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2653 if (data_buffer) {
2654 cb_state.AddChild(data_buffer);
2655 }
2656 } break;
2657 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2658 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2659 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2660 // easily ensure that's true.
2661 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2662 if (data_buffer) {
2663 cb_state.AddChild(data_buffer);
2664 }
2665 } break;
2666 default:
2667 break;
2668 }
2669 }
2670}
2671
sourav parmarcd5fb182020-07-17 12:58:44 -07002672void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2673 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2674 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002675 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002676 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002677 return;
2678 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002679 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002680 for (uint32_t i = 0; i < infoCount; i++) {
2681 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002682 }
sjfricke52defd42022-08-08 16:37:46 +09002683 cb_state->has_build_as_cmd = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07002684}
2685
2686void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2687 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2688 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2689 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002690 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2691 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002692 return;
2693 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002694 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002695 for (uint32_t i = 0; i < infoCount; i++) {
2696 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002697 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002698 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2699 if (indirect_buffer) {
2700 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002701 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002702 }
2703 }
sjfricke52defd42022-08-08 16:37:46 +09002704 cb_state->has_build_as_cmd = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07002705}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002706
locke-lunargd556cc32019-09-17 01:21:23 -06002707void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002708 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002709 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002710 if (as_state != nullptr) {
2711 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002712 as_state->memory_requirements_checked = true;
2713 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002714 as_state->build_scratch_memory_requirements_checked = true;
2715 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002716 as_state->update_scratch_memory_requirements_checked = true;
2717 }
2718 }
2719}
2720
sourav parmarcd5fb182020-07-17 12:58:44 -07002721void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2722 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002723 if (VK_SUCCESS != result) return;
2724 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002725 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002726
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002727 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002728 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002729 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002730 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002731 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02002732 as_state->BindMemory(as_state.get(), mem_state, info.memoryOffset, 0u, as_state->memory_requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002733 }
locke-lunargd556cc32019-09-17 01:21:23 -06002734
2735 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002736 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002737 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002738 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2739 }
2740 }
2741 }
2742}
2743
2744void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2745 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2746 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002747 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2748 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002749 return;
2750 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002751 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002752
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002753 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002754 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002755 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002756 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002757 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002758 }
locke-lunargd556cc32019-09-17 01:21:23 -06002759 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002760 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002761 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002762 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002763 cb_state->AddChild(src_as_state);
2764 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002765 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2766 if (instance_buffer) {
2767 cb_state->AddChild(instance_buffer);
2768 }
2769 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2770 if (scratch_buffer) {
2771 cb_state->AddChild(scratch_buffer);
2772 }
2773
2774 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2775 const auto& geom = pInfo->pGeometries[i];
2776
2777 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2778 if (vertex_buffer) {
2779 cb_state->AddChild(vertex_buffer);
2780 }
2781 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2782 if (index_buffer) {
2783 cb_state->AddChild(index_buffer);
2784 }
2785 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2786 if (transform_buffer) {
2787 cb_state->AddChild(transform_buffer);
2788 }
2789
2790 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2791 if (aabb_buffer) {
2792 cb_state->AddChild(aabb_buffer);
2793 }
2794 }
2795
locke-lunargd556cc32019-09-17 01:21:23 -06002796 }
sjfricke52defd42022-08-08 16:37:46 +09002797 cb_state->has_build_as_cmd = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002798}
2799
2800void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2801 VkAccelerationStructureNV dst,
2802 VkAccelerationStructureNV src,
2803 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002804 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002805 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002806 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2807 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002808 if (!disabled[command_buffer_state]) {
2809 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2810 }
locke-lunargd556cc32019-09-17 01:21:23 -06002811 if (dst_as_state != nullptr && src_as_state != nullptr) {
2812 dst_as_state->built = true;
2813 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002814 }
2815 }
2816}
2817
Jeff Bolz95176d02020-04-01 00:36:16 -05002818void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2819 VkAccelerationStructureKHR accelerationStructure,
2820 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002821 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002822}
2823
Jeff Bolz95176d02020-04-01 00:36:16 -05002824void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2825 VkAccelerationStructureNV accelerationStructure,
2826 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002827 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002828}
2829
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002830void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2831 uint32_t viewportCount,
2832 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002833 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002834 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002835}
2836
locke-lunargd556cc32019-09-17 01:21:23 -06002837void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002838 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002839 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002840}
2841
2842void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2843 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002844 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002845 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002846}
2847
2848void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2849 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002850 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002851 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002852}
2853
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002854void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2855 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002856 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002857 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002858 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2859 cb_state->scissorMask |= bits;
2860 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002861}
2862
locke-lunargd556cc32019-09-17 01:21:23 -06002863void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002864 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002865 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002866}
2867
2868void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2869 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002870 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002871 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002872}
2873
2874void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2875 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002876 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002877 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002878}
2879
2880void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2881 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002882 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002883 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002884}
2885
2886void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2887 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002888 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002889 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002890}
2891
locke-lunargd556cc32019-09-17 01:21:23 -06002892// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2893void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2894 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2895 uint32_t firstSet, uint32_t setCount,
2896 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2897 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002898 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002899 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002900 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002901 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002902
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002903 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2904 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002905}
2906
locke-lunargd556cc32019-09-17 01:21:23 -06002907void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2908 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2909 uint32_t set, uint32_t descriptorWriteCount,
2910 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002911 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002912 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002913 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002914}
2915
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002916void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2917 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2918 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002919 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2920 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002921 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002922 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2923 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002924
2925 auto &push_constant_data = cb_state->push_constant_data;
2926 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2927 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002928 cb_state->push_constant_pipeline_layout_set = layout;
2929
2930 auto flags = stageFlags;
2931 uint32_t bit_shift = 0;
2932 while (flags) {
2933 if (flags & 1) {
2934 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2935 const auto it = cb_state->push_constant_data_update.find(flag);
2936
2937 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002938 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002939 }
2940 }
2941 flags = flags >> 1;
2942 ++bit_shift;
2943 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002944 }
2945}
2946
locke-lunargd556cc32019-09-17 01:21:23 -06002947void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2948 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002949 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002950
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002951 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002952 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002953 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002954 cb_state->index_buffer_binding.offset = offset;
2955 cb_state->index_buffer_binding.index_type = indexType;
2956 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002957 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002958 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002959 }
locke-lunargd556cc32019-09-17 01:21:23 -06002960}
2961
2962void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2963 uint32_t bindingCount, const VkBuffer *pBuffers,
2964 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002965 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002966 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002967
2968 uint32_t end = firstBinding + bindingCount;
2969 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2970 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2971 }
2972
2973 for (uint32_t i = 0; i < bindingCount; ++i) {
2974 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002975 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002976 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002977 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2978 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002979 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002980 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002981 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002982 }
locke-lunargd556cc32019-09-17 01:21:23 -06002983 }
2984}
2985
2986void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2987 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002988 if (disabled[command_buffer_state]) return;
2989
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002990 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002991 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002992}
2993
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002994void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2995 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002996 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002997 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002998}
2999
3000void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3001 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003002 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003003 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3004
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003005 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
3006 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003007}
3008
Tony-LunarGc43525f2021-11-15 16:12:38 -07003009void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3010 const VkDependencyInfo* pDependencyInfo) {
3011 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3012 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3013
3014 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
3015 cb_state->RecordBarriers(*pDependencyInfo);
3016}
3017
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003018void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3019 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003020 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003021 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003022}
3023
3024void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3025 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003026 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003027 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003028}
3029
Tony-LunarGa2662db2021-11-16 07:26:24 -07003030void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3031 VkPipelineStageFlags2 stageMask) {
3032 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3033 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
3034}
3035
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003036void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3037 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
3038 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3039 uint32_t bufferMemoryBarrierCount,
3040 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3041 uint32_t imageMemoryBarrierCount,
3042 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003043 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3044 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003045 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3046 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003047}
3048
3049void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3050 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003051 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06003052 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003053 const auto &dep_info = pDependencyInfos[i];
3054 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3055 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
3056 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06003057 }
3058}
3059
Tony-LunarG1364cf52021-11-17 16:10:11 -07003060void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3061 const VkDependencyInfo *pDependencyInfos) {
3062 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3063 for (uint32_t i = 0; i < eventCount; i++) {
3064 const auto &dep_info = pDependencyInfos[i];
3065 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3066 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
3067 cb_state->RecordBarriers(dep_info);
3068 }
3069}
3070
Jeremy Gebben79649152021-06-22 14:46:24 -06003071void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3072 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3073 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3074 uint32_t bufferMemoryBarrierCount,
3075 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3076 uint32_t imageMemoryBarrierCount,
3077 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003078 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003079 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3080 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3081 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003082}
3083
3084void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3085 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003086 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003087 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3088 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003089}
3090
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07003091void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
3092 const VkDependencyInfo *pDependencyInfo) {
3093 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3094 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
3095 cb_state->RecordBarriers(*pDependencyInfo);
3096}
3097
locke-lunargd556cc32019-09-17 01:21:23 -06003098void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3099 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003100 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003101
locke-lunargd556cc32019-09-17 01:21:23 -06003102 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003103 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003104 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003105 if (!disabled[query_validation]) {
3106 cb_state->BeginQuery(query);
3107 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003108 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003109 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003110 cb_state->AddChild(pool_state);
3111 }
locke-lunargd556cc32019-09-17 01:21:23 -06003112}
3113
3114void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003115 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003116 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003117 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003118 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003119 if (!disabled[query_validation]) {
3120 cb_state->EndQuery(query_obj);
3121 }
3122 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003123 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003124 cb_state->AddChild(pool_state);
3125 }
locke-lunargd556cc32019-09-17 01:21:23 -06003126}
3127
3128void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3129 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003130 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003131 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003132
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003133 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003134 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003135
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003136 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003137 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003138 cb_state->AddChild(pool_state);
3139 }
locke-lunargd556cc32019-09-17 01:21:23 -06003140}
3141
3142void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3143 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3144 VkDeviceSize dstOffset, VkDeviceSize stride,
3145 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003146 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3147
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003148 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003149 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003150 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003151 cb_state->AddChild(dst_buff_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);
locke-lunargd556cc32019-09-17 01:21:23 -06003154}
3155
3156void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3157 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003158 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003159 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003160}
3161
3162void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3163 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3164 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003165 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003166 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003167}
3168
Tony-LunarGde9936b2021-11-17 15:34:11 -07003169void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3170 VkQueryPool queryPool, uint32_t slot) {
3171 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3172 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3173}
3174
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003175void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3176 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3177 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3178 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003179 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003180 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003181 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003182 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003183 cb_state->AddChild(pool_state);
3184 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003185 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003186}
3187
locke-lunargd556cc32019-09-17 01:21:23 -06003188void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3189 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3190 VkResult result) {
3191 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003192
Jeremy Gebben88f58142021-06-01 10:07:52 -06003193 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003194 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003195 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003196
locke-lunargd556cc32019-09-17 01:21:23 -06003197 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003198 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003199 }
3200 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003201
Jeremy Gebben9f537102021-10-05 16:37:12 -06003202 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003203 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003204}
3205
locke-lunargd556cc32019-09-17 01:21:23 -06003206void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3207 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3208 VkResult result) {
3209 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003210 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003211}
3212
Mike Schuchardt2df08912020-12-15 16:28:09 -08003213void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003214 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3215 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003216 if (VK_SUCCESS != result) return;
3217
Jeremy Gebben082a9832021-10-28 13:40:11 -06003218 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003219}
3220
Mike Schuchardt2df08912020-12-15 16:28:09 -08003221void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003222 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3223 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003224 if (VK_SUCCESS != result) return;
3225
Jeremy Gebben082a9832021-10-28 13:40:11 -06003226 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003227}
3228
locke-lunargd556cc32019-09-17 01:21:23 -06003229void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3230 const VkRenderPassBeginInfo *pRenderPassBegin,
3231 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003232 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003233 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003234}
3235
3236void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3237 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003238 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003239 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003240 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003241}
3242
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003243void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3244 uint32_t counterBufferCount,
3245 const VkBuffer *pCounterBuffers,
3246 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003247 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003248
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003249 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003250 cb_state->transform_feedback_active = true;
3251}
3252
3253void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3254 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3255 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003256 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003257
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003258 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003259 cb_state->transform_feedback_active = false;
3260}
3261
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003262void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3263 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003264 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003265
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003266 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003267 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003268 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3269 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003270}
3271
3272void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003273 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003274
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003275 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003276 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003277 cb_state->conditional_rendering_inside_render_pass = false;
3278 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003279}
3280
amhagana448ea52021-11-02 14:09:14 -04003281void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003282 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003283 cb_state->activeRenderPass = nullptr;
3284}
3285
3286void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3287 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003288 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003289 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3290}
3291
Tony-LunarG40b33882021-12-02 12:40:11 -07003292void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3293 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3294 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3295}
3296
amhagana448ea52021-11-02 14:09:14 -04003297void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3298 RecordCmdEndRenderingRenderPassState(commandBuffer);
3299}
3300
Tony-LunarG40b33882021-12-02 12:40:11 -07003301void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3302 RecordCmdEndRenderingRenderPassState(commandBuffer);
3303}
3304
Tony-LunarG977448c2019-12-02 14:52:02 -07003305void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3306 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003307 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003308 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003309 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003310}
3311
locke-lunargd556cc32019-09-17 01:21:23 -06003312void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003313 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003314 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003315}
3316
3317void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003318 const VkSubpassBeginInfo *pSubpassBeginInfo,
3319 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003320 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003321 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003322}
3323
Tony-LunarG977448c2019-12-02 14:52:02 -07003324void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003325 const VkSubpassBeginInfo *pSubpassBeginInfo,
3326 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003327 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003328 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003329}
3330
3331void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003332 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003333 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003334}
3335
3336void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003337 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003338 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003339 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003340}
3341
Tony-LunarG977448c2019-12-02 14:52:02 -07003342void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003343 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003344 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003345 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003346}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003347
locke-lunargd556cc32019-09-17 01:21:23 -06003348void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3349 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003350 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003351
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003352 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003353}
3354
3355void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3356 VkFlags flags, void **ppData, VkResult result) {
3357 if (VK_SUCCESS != result) return;
3358 RecordMappedMemory(mem, offset, size, ppData);
3359}
3360
3361void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003362 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003363 if (mem_info) {
3364 mem_info->mapped_range = MemRange();
3365 mem_info->p_driver_data = nullptr;
3366 }
3367}
3368
3369void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003370 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003371 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003372 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3373 // See: VUID-vkGetImageSubresourceLayout-image-01895
3374 image_state->fragment_encoder =
3375 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003376 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003377 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003378 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003379 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003380 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003381
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003382 if (!swapchain_image.fake_base_address) {
3383 auto size = image_state->fragment_encoder->TotalSize();
3384 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003385 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003386 // All images bound to this swapchain and index are aliases
3387 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003388 }
3389 } else {
3390 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003391 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003392 if (mem_info) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02003393 VkDeviceSize plane_index = 0u;
3394 if (image_state->disjoint && image_state->IsExternalAHB() == false) {
3395 auto plane_info = LvlFindInChain<VkBindImagePlaneMemoryInfo>(bindInfo.pNext);
3396 const VkImageAspectFlagBits aspect = plane_info->planeAspect;
3397 switch (aspect) {
3398 case VK_IMAGE_ASPECT_PLANE_0_BIT:
3399 plane_index = 0;
3400 break;
3401 case VK_IMAGE_ASPECT_PLANE_1_BIT:
3402 plane_index = 1;
3403 break;
3404 case VK_IMAGE_ASPECT_PLANE_2_BIT:
3405 plane_index = 2;
3406 break;
3407 default:
3408 assert(false); // parameter validation should have caught this
3409 break;
3410 }
3411 }
3412 image_state->BindMemory(
3413 image_state.get(), mem_info, bindInfo.memoryOffset, plane_index,
3414 image_state->requirements[static_cast<decltype(image_state->requirements)::size_type>(plane_index)].size);
locke-lunargd556cc32019-09-17 01:21:23 -06003415 }
locke-lunargd556cc32019-09-17 01:21:23 -06003416 }
locke-lunargd556cc32019-09-17 01:21:23 -06003417 }
3418}
3419
3420void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3421 VkDeviceSize memoryOffset, VkResult result) {
3422 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003423 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003424 bind_info.image = image;
3425 bind_info.memory = mem;
3426 bind_info.memoryOffset = memoryOffset;
3427 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003428}
3429
3430void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003431 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003432 if (VK_SUCCESS != result) return;
3433 for (uint32_t i = 0; i < bindInfoCount; i++) {
3434 UpdateBindImageMemoryState(pBindInfos[i]);
3435 }
3436}
3437
3438void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003439 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003440 if (VK_SUCCESS != result) return;
3441 for (uint32_t i = 0; i < bindInfoCount; i++) {
3442 UpdateBindImageMemoryState(pBindInfos[i]);
3443 }
3444}
3445
3446void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003447 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003448 if (event_state) {
3449 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3450 }
locke-lunargd556cc32019-09-17 01:21:23 -06003451}
3452
3453void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3454 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3455 VkResult result) {
3456 if (VK_SUCCESS != result) return;
3457 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3458 pImportSemaphoreFdInfo->flags);
3459}
3460
3461void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003462 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003463 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003464 if (semaphore_state) {
3465 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003466 }
3467}
3468
3469#ifdef VK_USE_PLATFORM_WIN32_KHR
3470void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3471 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3472 if (VK_SUCCESS != result) return;
3473 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3474 pImportSemaphoreWin32HandleInfo->flags);
3475}
3476
3477void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3478 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3479 HANDLE *pHandle, VkResult result) {
3480 if (VK_SUCCESS != result) return;
3481 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3482}
3483
3484void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3485 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3486 if (VK_SUCCESS != result) return;
3487 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3488 pImportFenceWin32HandleInfo->flags);
3489}
3490
3491void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3492 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3493 HANDLE *pHandle, VkResult result) {
3494 if (VK_SUCCESS != result) return;
3495 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3496}
3497#endif
3498
3499void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3500 VkResult result) {
3501 if (VK_SUCCESS != result) return;
3502 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3503}
3504
Mike Schuchardt2df08912020-12-15 16:28:09 -08003505void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3506 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003507 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003508
3509 if (fence_node) {
3510 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003511 }
3512}
3513
3514void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3515 VkResult result) {
3516 if (VK_SUCCESS != result) return;
3517 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3518}
3519
Mike Schuchardt2df08912020-12-15 16:28:09 -08003520void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003521 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003522 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003523 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003524 }
3525}
3526
3527void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3528 VkResult result) {
3529 if (VK_SUCCESS != result) return;
3530 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3531}
3532
3533void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3534 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3535 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06003536 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003537}
3538
3539void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003540 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003541 SWAPCHAIN_NODE *old_swapchain_state) {
3542 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003543 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003544 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003545 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003546 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3547 surface_state->AddParent(swapchain.get());
3548 surface_state->swapchain = swapchain.get();
3549 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003550 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003551 } else {
3552 surface_state->swapchain = nullptr;
3553 }
3554 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003555 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003556 if (old_swapchain_state) {
3557 old_swapchain_state->retired = true;
3558 }
3559 return;
3560}
3561
3562void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3563 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3564 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003565 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003566 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003567 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003568}
3569
3570void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3571 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003572 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003573}
3574
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003575void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3576 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3577 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3578 VkResult result) {
3579 if (VK_SUCCESS != result) return;
3580 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003581 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003582}
3583
locke-lunargd556cc32019-09-17 01:21:23 -06003584void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003585 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003586 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003587 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3588 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3589 if (semaphore_state) {
3590 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003591 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003592 }
3593
3594 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3595 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3596 // 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
3597 // confused itself just as much.
3598 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3599 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3600 // Mark the image as having been released to the WSI
3601 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3602 if (swapchain_data) {
3603 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3604 if (present_id_info) {
3605 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3606 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3607 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003608 }
3609 }
locke-lunargd556cc32019-09-17 01:21:23 -06003610 }
locke-lunargd556cc32019-09-17 01:21:23 -06003611}
3612
3613void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3614 const VkSwapchainCreateInfoKHR *pCreateInfos,
3615 const VkAllocationCallbacks *pAllocator,
3616 VkSwapchainKHR *pSwapchains, VkResult result) {
3617 if (pCreateInfos) {
3618 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003619 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003620 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003621 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3622 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003623 }
3624 }
3625}
3626
3627void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3628 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003629 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003630 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003631 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3632 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003633 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003634 }
3635
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003636 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003637 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003638 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3639 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003640 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003641 }
3642
3643 // Mark the image as acquired.
3644 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3645 if (swapchain_data) {
3646 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003647 }
3648}
3649
3650void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3651 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3652 VkResult result) {
3653 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3654 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3655}
3656
3657void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3658 uint32_t *pImageIndex, VkResult result) {
3659 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3660 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3661 pAcquireInfo->fence, pImageIndex);
3662}
3663
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003664std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3665 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3666}
3667
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003668void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3669 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3670 VkResult result) {
3671 if (result != VK_SUCCESS) {
3672 return;
3673 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003674 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003675 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003676 // this can fail if the allocator fails
3677 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3678 if (result != VK_SUCCESS) {
3679 return;
3680 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003681 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003682 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3683 if (result != VK_SUCCESS) {
3684 return;
3685 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003686
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003687 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003688 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003689 }
Tony-LunarGffb5b522022-06-15 15:49:27 -06003690
3691#ifdef VK_USE_PLATFORM_METAL_EXT
3692 auto export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(pCreateInfo->pNext);
3693 while (export_metal_object_info) {
3694 export_metal_flags.push_back(export_metal_object_info->exportObjectType);
3695 export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(export_metal_object_info->pNext);
3696 }
3697#endif // VK_USE_PLATFORM_METAL_EXT
locke-lunargd556cc32019-09-17 01:21:23 -06003698}
3699
Tony-LunarGffb5b522022-06-15 15:49:27 -06003700
locke-lunargd556cc32019-09-17 01:21:23 -06003701// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003702static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003703 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003704}
3705
3706void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3707 uint32_t *pQueueFamilyPropertyCount,
3708 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003709 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3710 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003711 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003712}
3713
3714void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003715 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003716 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3717 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003718 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003719}
3720
3721void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003722 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003723 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3724 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003725 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003726}
3727void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3728 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003729 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003730}
3731
Jeremy Gebben082a9832021-10-28 13:40:11 -06003732void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003733
3734void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3735 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3736 const VkAllocationCallbacks *pAllocator,
3737 VkSurfaceKHR *pSurface, VkResult result) {
3738 if (VK_SUCCESS != result) return;
3739 RecordVulkanSurface(pSurface);
3740}
3741
3742#ifdef VK_USE_PLATFORM_ANDROID_KHR
3743void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3744 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3745 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3746 VkResult result) {
3747 if (VK_SUCCESS != result) return;
3748 RecordVulkanSurface(pSurface);
3749}
3750#endif // VK_USE_PLATFORM_ANDROID_KHR
3751
3752#ifdef VK_USE_PLATFORM_IOS_MVK
3753void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3754 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3755 VkResult result) {
3756 if (VK_SUCCESS != result) return;
3757 RecordVulkanSurface(pSurface);
3758}
3759#endif // VK_USE_PLATFORM_IOS_MVK
3760
3761#ifdef VK_USE_PLATFORM_MACOS_MVK
3762void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3763 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3764 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3765 VkResult result) {
3766 if (VK_SUCCESS != result) return;
3767 RecordVulkanSurface(pSurface);
3768}
3769#endif // VK_USE_PLATFORM_MACOS_MVK
3770
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003771#ifdef VK_USE_PLATFORM_METAL_EXT
3772void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3773 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3774 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3775 VkResult result) {
3776 if (VK_SUCCESS != result) return;
3777 RecordVulkanSurface(pSurface);
3778}
3779#endif // VK_USE_PLATFORM_METAL_EXT
3780
locke-lunargd556cc32019-09-17 01:21:23 -06003781#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3782void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3783 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3784 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3785 VkResult result) {
3786 if (VK_SUCCESS != result) return;
3787 RecordVulkanSurface(pSurface);
3788}
3789#endif // VK_USE_PLATFORM_WAYLAND_KHR
3790
3791#ifdef VK_USE_PLATFORM_WIN32_KHR
3792void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3793 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3794 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3795 VkResult result) {
3796 if (VK_SUCCESS != result) return;
3797 RecordVulkanSurface(pSurface);
3798}
3799#endif // VK_USE_PLATFORM_WIN32_KHR
3800
3801#ifdef VK_USE_PLATFORM_XCB_KHR
3802void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3803 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3804 VkResult result) {
3805 if (VK_SUCCESS != result) return;
3806 RecordVulkanSurface(pSurface);
3807}
3808#endif // VK_USE_PLATFORM_XCB_KHR
3809
3810#ifdef VK_USE_PLATFORM_XLIB_KHR
3811void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3812 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3813 VkResult result) {
3814 if (VK_SUCCESS != result) return;
3815 RecordVulkanSurface(pSurface);
3816}
3817#endif // VK_USE_PLATFORM_XLIB_KHR
3818
Niklas Haas8b84af12020-04-19 22:20:11 +02003819void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3820 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3821 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3822 VkResult result) {
3823 if (VK_SUCCESS != result) return;
3824 RecordVulkanSurface(pSurface);
3825}
3826
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003827void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3828 VkSurfaceKHR surface,
3829 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3830 VkResult result) {
3831 if (VK_SUCCESS != result) return;
3832 auto surface_state = Get<SURFACE_STATE>(surface);
3833 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3834}
3835
3836void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3837 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3838 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3839 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003840
3841 if (pSurfaceInfo->surface) {
3842 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3843 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3844 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3845 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3846 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3847 assert(pd_state);
3848 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3849 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003850}
3851
3852void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3853 VkSurfaceKHR surface,
3854 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3855 VkResult result) {
3856 auto surface_state = Get<SURFACE_STATE>(surface);
3857 VkSurfaceCapabilitiesKHR caps{
3858 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3859 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3860 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3861 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3862 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3863 };
3864 surface_state->SetCapabilities(physicalDevice, caps);
3865}
3866
locke-lunargd556cc32019-09-17 01:21:23 -06003867void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3868 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3869 VkBool32 *pSupported, VkResult result) {
3870 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003871 auto surface_state = Get<SURFACE_STATE>(surface);
3872 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3873}
3874
3875void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3876 VkSurfaceKHR surface,
3877 uint32_t *pPresentModeCount,
3878 VkPresentModeKHR *pPresentModes,
3879 VkResult result) {
3880 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3881
3882 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003883 if (surface) {
3884 auto surface_state = Get<SURFACE_STATE>(surface);
3885 surface_state->SetPresentModes(physicalDevice,
3886 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3887 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3888 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3889 assert(pd_state);
3890 pd_state->surfaceless_query_state.present_modes =
3891 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3892 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003893 }
3894}
3895
3896void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3897 uint32_t *pSurfaceFormatCount,
3898 VkSurfaceFormatKHR *pSurfaceFormats,
3899 VkResult result) {
3900 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3901
3902 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003903 if (surface) {
3904 auto surface_state = Get<SURFACE_STATE>(surface);
3905 surface_state->SetFormats(physicalDevice,
3906 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3907 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3908 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3909 assert(pd_state);
3910 pd_state->surfaceless_query_state.formats =
3911 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3912 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003913 }
3914}
3915
3916void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3917 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3918 uint32_t *pSurfaceFormatCount,
3919 VkSurfaceFormat2KHR *pSurfaceFormats,
3920 VkResult result) {
3921 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3922
3923 if (pSurfaceFormats) {
3924 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003925 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3926 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3927 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003928 if (pSurfaceInfo->surface) {
3929 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3930 surface_state->SetFormats(physicalDevice, std::move(fmts));
3931 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3932 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3933 assert(pd_state);
3934 pd_state->surfaceless_query_state.formats = std::move(fmts);
3935 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003936 }
locke-lunargd556cc32019-09-17 01:21:23 -06003937}
3938
locke-lunargd556cc32019-09-17 01:21:23 -06003939void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3940 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003941 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003942 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003943 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3944}
3945
3946void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003947 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003948 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003949 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3950}
3951
3952void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3953 const VkDebugUtilsLabelEXT *pLabelInfo) {
3954 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3955
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_INSERTDEBUGUTILSLABELEXT);
3958 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003959 cb_state->debug_label = LoggingLabel(pLabelInfo);
3960}
3961
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003962void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3963 uint32_t queueFamilyIndex,
3964 uint32_t *pCounterCount,
3965 VkPerformanceCounterKHR *pCounters) {
3966 if (NULL == pCounters) return;
3967
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003968 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3969 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003970
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003971 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3972 queue_family_counters->counters.resize(*pCounterCount);
3973 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003974
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003975 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003976}
3977
3978void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3979 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3980 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3981 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3982 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3983}
3984
3985void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3986 VkResult result) {
3987 if (result == VK_SUCCESS) performance_lock_acquired = true;
3988}
3989
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003990void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3991 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003992 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003993 cmd_buffer.second->performance_lock_released = true;
3994 }
3995}
3996
locke-lunargd556cc32019-09-17 01:21:23 -06003997void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003998 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003999 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004000 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004001}
4002
4003void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004004 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004005 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004006 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004007}
4008
Mike Schuchardt2df08912020-12-15 16:28:09 -08004009void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4010 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004011 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06004012}
4013
Mike Schuchardt2df08912020-12-15 16:28:09 -08004014void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
4015 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4016 const VkAllocationCallbacks *pAllocator,
4017 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
4018 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004019 if (VK_SUCCESS != result) return;
4020 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4021}
4022
4023void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08004024 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4025 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004026 if (VK_SUCCESS != result) return;
4027 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4028}
4029
4030void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004031 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004032 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004033 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
4034 assert(template_state);
4035 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06004036 // TODO: Record template push descriptor updates
4037 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004038 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06004039 }
4040 }
4041}
4042
4043void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
4044 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4045 const void *pData) {
4046 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4047}
4048
4049void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004050 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004051 const void *pData) {
4052 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4053}
4054
Mike Schuchardt2df08912020-12-15 16:28:09 -08004055void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
4056 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4057 VkPipelineLayout layout, uint32_t set,
4058 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004059 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004060
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004061 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07004062 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004063 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004064 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06004065 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004066 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004067 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06004068 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004069 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06004070 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004071 static_cast<uint32_t>(decoded_template.desc_writes.size()),
4072 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06004073 }
4074}
4075
4076void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
4077 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004078 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06004079 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004080 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004081 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06004082 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004083 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004084 }
4085}
4086
4087void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
4088 uint32_t *pPropertyCount,
4089 VkDisplayPlanePropertiesKHR *pProperties,
4090 VkResult result) {
4091 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4092 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4093}
4094
4095void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
4096 uint32_t *pPropertyCount,
4097 VkDisplayPlaneProperties2KHR *pProperties,
4098 VkResult result) {
4099 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4100 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4101}
4102
4103void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4104 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
4105 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004106 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004107 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004108 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004109}
4110
4111void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4112 uint32_t query, uint32_t index) {
4113 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004114 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004115 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004116 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004117}
4118
4119void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4120 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02004121 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004122
4123 if (create_info->format != VK_FORMAT_UNDEFINED) {
4124 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07004125 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004126 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4127 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004128 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004129
Jeremy Gebben082a9832021-10-28 13:40:11 -06004130 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004131}
4132
4133void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4134 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4135 const VkAllocationCallbacks *pAllocator,
4136 VkSamplerYcbcrConversion *pYcbcrConversion,
4137 VkResult result) {
4138 if (VK_SUCCESS != result) return;
4139 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4140}
4141
4142void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4143 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4144 const VkAllocationCallbacks *pAllocator,
4145 VkSamplerYcbcrConversion *pYcbcrConversion,
4146 VkResult result) {
4147 if (VK_SUCCESS != result) return;
4148 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4149}
4150
4151void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4152 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004153 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004154}
4155
4156void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4157 VkSamplerYcbcrConversion ycbcrConversion,
4158 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004159 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004160}
4161
Tony-LunarG977448c2019-12-02 14:52:02 -07004162void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4163 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004164 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004165 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004166
4167 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004168 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004169 if (!query_pool_state) return;
4170
4171 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004172 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4173 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004174 auto query_index = firstQuery + i;
4175 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004176 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004177 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004178 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004179 }
4180 }
locke-lunargd556cc32019-09-17 01:21:23 -06004181 }
4182}
4183
Tony-LunarG977448c2019-12-02 14:52:02 -07004184void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4185 uint32_t queryCount) {
4186 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4187}
4188
4189void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4190 uint32_t queryCount) {
4191 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4192}
4193
locke-lunargd556cc32019-09-17 01:21:23 -06004194void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004195 const UPDATE_TEMPLATE_STATE *template_state,
4196 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004197 // Translate the templated update into a normal update for validation...
4198 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4199 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4200 decoded_update.desc_writes.data(), 0, NULL);
4201}
4202
4203// Update the common AllocateDescriptorSetsData
4204void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004205 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004206 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004207 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004208 if (layout) {
4209 ds_data->layout_nodes[i] = layout;
4210 // Count total descriptors required per type
4211 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4212 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004213 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4214 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004215 }
4216 }
4217 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4218 }
4219}
4220
locke-lunargd556cc32019-09-17 01:21:23 -06004221void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4222 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004223 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004224 cb_state->UpdateDrawCmd(CMD_DRAW);
locke-lunargd556cc32019-09-17 01:21:23 -06004225}
4226
Tony-LunarG745150c2021-07-02 15:07:31 -06004227void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4228 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4229 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004230 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004231 cb_state->UpdateDrawCmd(CMD_DRAWMULTIEXT);
Tony-LunarG745150c2021-07-02 15:07:31 -06004232}
4233
locke-lunargd556cc32019-09-17 01:21:23 -06004234void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4235 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4236 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004237 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004238 cb_state->UpdateDrawCmd(CMD_DRAWINDEXED);
locke-lunargd556cc32019-09-17 01:21:23 -06004239}
4240
Tony-LunarG745150c2021-07-02 15:07:31 -06004241void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4242 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4243 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4244 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004245 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004246 cb_state->UpdateDrawCmd(CMD_DRAWMULTIINDEXEDEXT);
Tony-LunarG745150c2021-07-02 15:07:31 -06004247}
4248
locke-lunargd556cc32019-09-17 01:21:23 -06004249void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4250 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004251 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004252 auto buffer_state = Get<BUFFER_STATE>(buffer);
sjfricke52defd42022-08-08 16:37:46 +09004253 cb_state->UpdateDrawCmd(CMD_DRAWINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004254 if (!disabled[command_buffer_state]) {
4255 cb_state->AddChild(buffer_state);
4256 }
locke-lunargd556cc32019-09-17 01:21:23 -06004257}
4258
4259void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4260 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004261 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004262 auto buffer_state = Get<BUFFER_STATE>(buffer);
sjfricke52defd42022-08-08 16:37:46 +09004263 cb_state->UpdateDrawCmd(CMD_DRAWINDEXEDINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004264 if (!disabled[command_buffer_state]) {
4265 cb_state->AddChild(buffer_state);
4266 }
locke-lunargd556cc32019-09-17 01:21:23 -06004267}
4268
4269void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
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->UpdateDispatchCmd(CMD_DISPATCH);
locke-lunargd556cc32019-09-17 01:21:23 -06004272}
4273
4274void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4275 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004276 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004277 cb_state->UpdateDispatchCmd(CMD_DISPATCHINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004278 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004279 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004280 cb_state->AddChild(buffer_state);
4281 }
locke-lunargd556cc32019-09-17 01:21:23 -06004282}
4283
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004284void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4285 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004286 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004287 cb_state->UpdateDispatchCmd(CMD_DISPATCHBASEKHR);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004288}
4289
4290void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4291 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004292 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004293 cb_state->UpdateDispatchCmd(CMD_DISPATCHBASE);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004294}
4295
Tony-LunarG977448c2019-12-02 14:52:02 -07004296void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4297 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004298 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004299 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004300 cb_state->UpdateDrawCmd(cmd_type);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004301 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004302 auto buffer_state = Get<BUFFER_STATE>(buffer);
4303 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004304 cb_state->AddChild(buffer_state);
4305 cb_state->AddChild(count_buffer_state);
4306 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004307}
4308
locke-lunargd556cc32019-09-17 01:21:23 -06004309void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4310 VkDeviceSize offset, VkBuffer countBuffer,
4311 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4312 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004313 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004314 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004315}
4316
4317void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4318 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4319 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004320 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004321 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004322}
4323
4324void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4325 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004326 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004327 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004328 cb_state->UpdateDrawCmd(cmd_type);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004329 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004330 auto buffer_state = Get<BUFFER_STATE>(buffer);
4331 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004332 cb_state->AddChild(buffer_state);
4333 cb_state->AddChild(count_buffer_state);
4334 }
locke-lunargd556cc32019-09-17 01:21:23 -06004335}
4336
4337void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4338 VkDeviceSize offset, VkBuffer countBuffer,
4339 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4340 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004341 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004342 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004343}
4344
4345void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4346 VkDeviceSize offset, VkBuffer countBuffer,
4347 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4348 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004349 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004350 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004351}
4352
4353void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4354 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004355 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004356 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSNV);
locke-lunargd556cc32019-09-17 01:21:23 -06004357}
4358
4359void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4360 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004361 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004362 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTNV);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004363 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004364 if (!disabled[command_buffer_state] && buffer_state) {
4365 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004366 }
4367}
4368
4369void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4370 VkDeviceSize offset, VkBuffer countBuffer,
4371 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4372 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004373 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004374 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTCOUNTNV);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004375 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004376 auto buffer_state = Get<BUFFER_STATE>(buffer);
4377 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004378 if (buffer_state) {
4379 cb_state->AddChild(buffer_state);
4380 }
4381 if (count_buffer_state) {
4382 cb_state->AddChild(count_buffer_state);
4383 }
locke-lunargd556cc32019-09-17 01:21:23 -06004384 }
4385}
4386
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004387void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4388 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4389 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4390 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4391 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4392 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4393 uint32_t width, uint32_t height, uint32_t depth) {
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->UpdateTraceRayCmd(CMD_TRACERAYSNV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004396}
4397
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004398void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4399 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4400 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4401 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4402 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4403 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004404 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004405 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSKHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004406}
4407
4408void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4409 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4410 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4411 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4412 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4413 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004414 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004415 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECTKHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004416}
4417
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004418std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4419 uint32_t unique_shader_id) const {
4420 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4421 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4422 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4423 : std::make_shared<SHADER_MODULE_STATE>();
4424}
4425
4426std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4427 uint32_t unique_shader_id,
4428 VkShaderModule handle) const {
4429 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4430 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4431 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4432 : std::make_shared<SHADER_MODULE_STATE>();
4433}
4434
sfricke-samsungf91881c2022-03-31 01:12:00 -05004435void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer,
4436 VkDeviceAddress indirectDeviceAddress) {
4437 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004438 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECT2KHR);
sfricke-samsungf91881c2022-03-31 01:12:00 -05004439}
4440
locke-lunargd556cc32019-09-17 01:21:23 -06004441void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4442 const VkAllocationCallbacks *pAllocator,
4443 VkShaderModule *pShaderModule, VkResult result,
4444 void *csm_state_data) {
4445 if (VK_SUCCESS != result) return;
4446 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4447
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004448 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004449}
4450
John Zulauf22b0fbe2019-10-15 06:26:16 -06004451void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4452 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4453 VkResult result) {
4454 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004455 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004456
4457 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4458
4459 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004460 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004461 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004462 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004463
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004464 auto format_features = GetImageFormatFeatures(
4465 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4466 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004467
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004468 auto image_state =
4469 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004470 if (!swapchain_image.fake_base_address) {
4471 auto size = image_state->fragment_encoder->TotalSize();
4472 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004473 }
4474
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004475 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004476 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004477 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004478 }
4479 }
4480
4481 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004482 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4483 }
4484}
sourav parmar35e7a002020-06-09 17:58:44 -07004485
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004486void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4487 const VkCopyAccelerationStructureInfoKHR *pInfo,
4488 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004489 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4490 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004491 if (dst_as_state != nullptr && src_as_state != nullptr) {
4492 dst_as_state->built = true;
4493 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4494 }
4495}
4496
sourav parmar35e7a002020-06-09 17:58:44 -07004497void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4498 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004499 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004500 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004501 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004502 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4503 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004504 if (dst_as_state != nullptr && src_as_state != nullptr) {
4505 dst_as_state->built = true;
4506 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004507 if (!disabled[command_buffer_state]) {
4508 cb_state->AddChild(dst_as_state);
4509 cb_state->AddChild(src_as_state);
4510 }
sourav parmar35e7a002020-06-09 17:58:44 -07004511 }
4512 }
4513}
Piers Daniell39842ee2020-07-10 16:42:33 -06004514
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004515void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4516 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4517 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4518 if (cb_state) {
4519 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4520 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4521 if (!disabled[command_buffer_state]) {
4522 cb_state->AddChild(src_as_state);
4523 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004524 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4525 if (dst_buffer) {
4526 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004527 }
4528 }
4529}
4530
4531void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4532 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4533 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4534 if (cb_state) {
4535 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4536 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004537 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4538 if (buffer_state) {
4539 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004540 }
4541 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4542 cb_state->AddChild(dst_as_state);
4543 }
4544 }
4545}
4546
Piers Daniell39842ee2020-07-10 16:42:33 -06004547void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004548 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004549 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004550}
4551
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004552void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4553 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4554 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4555}
4556
Piers Daniell39842ee2020-07-10 16:42:33 -06004557void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004558 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004559 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004560}
4561
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004562void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4563 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4564 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4565}
4566
Piers Daniell39842ee2020-07-10 16:42:33 -06004567void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4568 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004569 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004570 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004571 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004572}
4573
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004574void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4575 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004576 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004577 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4578 cb_state->primitiveTopology = primitiveTopology;
4579}
4580
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004581void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4582 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004583 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4584 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004585 uint32_t bits = (1u << viewportCount) - 1u;
4586 cb_state->viewportWithCountMask |= bits;
4587 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004588 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004589 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004590
4591 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4592 for (size_t i = 0; i < viewportCount; ++i) {
4593 cb_state->dynamicViewports[i] = pViewports[i];
4594 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004595}
4596
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004597void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4598 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004599 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004600}
4601
4602void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004603 const VkViewport *pViewports) {
4604 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004605}
4606
4607void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4608 const VkRect2D *pScissors, CMD_TYPE cmdType) {
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(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004611 uint32_t bits = (1u << scissorCount) - 1u;
4612 cb_state->scissorWithCountMask |= bits;
4613 cb_state->trashedScissorMask &= ~bits;
4614 cb_state->scissorWithCountCount = scissorCount;
4615 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004616}
4617
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004618void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4619 const VkRect2D *pScissors) {
4620 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4621}
4622
4623void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4624 const VkRect2D *pScissors) {
4625 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4626}
4627
4628void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4629 uint32_t bindingCount, const VkBuffer *pBuffers,
4630 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4631 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004632 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004633 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004634
4635 uint32_t end = firstBinding + bindingCount;
4636 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4637 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4638 }
4639
4640 for (uint32_t i = 0; i < bindingCount; ++i) {
4641 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004642 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004643 vertex_buffer_binding.offset = pOffsets[i];
4644 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4645 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4646 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004647 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004648 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004649 }
4650 }
4651}
4652
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004653void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4654 uint32_t bindingCount, const VkBuffer *pBuffers,
4655 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4656 const VkDeviceSize *pStrides) {
4657 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4658 CMD_BINDVERTEXBUFFERS2EXT);
4659}
4660
4661void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4662 uint32_t bindingCount, const VkBuffer *pBuffers,
4663 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4664 const VkDeviceSize *pStrides) {
4665 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4666 CMD_BINDVERTEXBUFFERS2);
4667}
4668
Piers Daniell39842ee2020-07-10 16:42:33 -06004669void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004670 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004671 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004672}
4673
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004674void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4675 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4676 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4677}
4678
Piers Daniell39842ee2020-07-10 16:42:33 -06004679void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004680 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004681 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004682}
4683
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004684void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4685 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4686 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4687}
4688
Piers Daniell39842ee2020-07-10 16:42:33 -06004689void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004690 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004691 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004692}
4693
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004694void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4695 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4696 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4697}
4698
Piers Daniell39842ee2020-07-10 16:42:33 -06004699void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4700 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004701 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004702 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004703}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004704
4705void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4706 VkBool32 depthBoundsTestEnable) {
4707 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4708 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4709}
4710
Piers Daniell39842ee2020-07-10 16:42:33 -06004711void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004712 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004713 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004714}
4715
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004716void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4717 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4718 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4719}
4720
Piers Daniell39842ee2020-07-10 16:42:33 -06004721void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4722 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4723 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004724 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004725 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004726}
locke-lunarg4189aa22020-10-21 00:23:48 -06004727
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004728void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4729 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4730 VkCompareOp compareOp) {
4731 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4732 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4733}
4734
locke-lunarg4189aa22020-10-21 00:23:48 -06004735void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4736 uint32_t discardRectangleCount,
4737 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004738 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004739 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004740}
4741
4742void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4743 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004744 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004745 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004746}
4747
4748void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4749 VkCoarseSampleOrderTypeNV sampleOrderType,
4750 uint32_t customSampleOrderCount,
4751 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004752 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004753 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004754}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004755
4756void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
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_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004759}
4760
4761void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004762 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004763 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004764}
4765
4766void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4767 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004768 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004769 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004770 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004771}
4772
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004773void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4774 VkBool32 rasterizerDiscardEnable) {
4775 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4776 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004777 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004778}
4779
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004780void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004781 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004782 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004783}
4784
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004785void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4786 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4787 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4788}
4789
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004790void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4791 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004792 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004793 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004794}
Piers Daniell924cd832021-05-18 13:48:47 -06004795
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004796void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4797 VkBool32 primitiveRestartEnable) {
4798 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4799 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4800}
4801
Piers Daniell924cd832021-05-18 13:48:47 -06004802void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4803 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4804 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4805 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004806 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004807 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4808
4809 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4810 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4811 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004812 const auto *dynamic_state = pipeline_state->DynamicState();
4813 if (dynamic_state) {
4814 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4815 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004816 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4817 break;
4818 }
4819 }
4820 }
4821 }
4822 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004823}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004824
ziga-lunarg67b7c392022-03-26 01:45:34 +01004825void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4826 const VkBool32 *pColorWriteEnables) {
4827 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4828 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4829 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4830}
4831
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004832void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004833 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004834 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004835 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004836 // address is used for GPU-AV and ray tracing buffer validation
4837 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004838 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004839 }
4840}
4841
4842void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4843 VkDeviceAddress address) {
4844 RecordGetBufferDeviceAddress(pInfo, address);
4845}
4846
4847void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4848 VkDeviceAddress address) {
4849 RecordGetBufferDeviceAddress(pInfo, address);
4850}
4851
4852void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4853 VkDeviceAddress address) {
4854 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004855}
4856
4857std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4858 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004859 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004860}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004861
4862std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4863 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004864 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004865 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4866}