blob: 8b12bec605464ab1833c10bedbec4aaf9af40d70 [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Tobias Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Dave Houlton <daveh@lunarg.com>
21 * Shannon McPherson <shannon@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
28#include "vk_enum_string_helper.h"
29#include "vk_format_utils.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33#include "vk_typemap_helper.h"
34
35#include "chassis.h"
36#include "state_tracker.h"
37#include "shader_validation.h"
Jeremy Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
sjfrickee9b39372022-05-22 13:02:17 +0900137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200138
139 // Find the image modifier
140 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
141
142 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
143 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
144 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
145
146 // Second query to have all the modifiers filled
147 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
148
149 // Look for the image modifier in the list
150 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
151 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
152 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
153 break;
154 }
155 }
156 } else {
157 format_features =
158 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
159 }
160 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
sjfrickee9b39372022-05-22 13:02:17 +0900161 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600162 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200163
sjfrickee9b39372022-05-22 13:02:17 +0900164 VkFormatProperties2 format_properties_2 = LvlInitStruct<VkFormatProperties2>();
165 VkDrmFormatModifierPropertiesListEXT drm_properties_list = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600166 format_properties_2.pNext = (void *)&drm_properties_list;
167 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
168 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
169 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
170 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
171 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200172
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600173 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
174 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
175 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
176 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200177 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200178 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600179 } else {
180 VkFormatProperties format_properties;
181 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
182 format_features =
183 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200184 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600185 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200186}
187
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700188std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
189 VkFormatFeatureFlags2KHR features) {
Aitor Camacho3294edd2022-05-16 22:34:19 +0200190 std::shared_ptr<IMAGE_STATE> state;
191
192 if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
193 if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) {
194 state = std::make_shared<IMAGE_STATE_SPARSE<true>>(this, img, pCreateInfo, features);
195 } else {
196 state = std::make_shared<IMAGE_STATE_SPARSE<false>>(this, img, pCreateInfo, features);
197 }
198 } else if (pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
199 uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
200 switch (plane_count) {
201 case 3:
202 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<3>>(this, img, pCreateInfo, features);
203 break;
204 case 2:
205 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<2>>(this, img, pCreateInfo, features);
206 break;
207 case 1:
208 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<1>>(this, img, pCreateInfo, features);
209 break;
210 default:
Shahbaz Youssefi87f53002022-06-07 10:14:01 -0400211 // Not supported
212 assert(false);
Aitor Camacho3294edd2022-05-16 22:34:19 +0200213 }
214 } else {
215 state = std::make_shared<IMAGE_STATE_LINEAR>(this, img, pCreateInfo, features);
216 }
217
218 return state;
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700219}
220
221std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
222 VkSwapchainKHR swapchain, uint32_t swapchain_index,
223 VkFormatFeatureFlags2KHR features) {
Aitor Camacho3294edd2022-05-16 22:34:19 +0200224 return std::make_shared<IMAGE_STATE_NO_BINDING>(this, img, pCreateInfo, swapchain, swapchain_index, features);
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700225}
226
locke-lunargd556cc32019-09-17 01:21:23 -0600227void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
228 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
229 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200230 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700231 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600232 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600233 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600234 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200235 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
236 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
237 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600238 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700239 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600240}
241
242void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600243 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600244}
245
246void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
247 VkImageLayout imageLayout, const VkClearColorValue *pColor,
248 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600252 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600253 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600254 }
255}
256
257void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
258 VkImageLayout imageLayout,
259 const VkClearDepthStencilValue *pDepthStencil,
260 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600261 if (disabled[command_buffer_state]) return;
262
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700263 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600264 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600265 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600266 }
267}
268
269void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
270 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
271 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600272 if (disabled[command_buffer_state]) return;
273
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700274 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600275 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600276}
277
Jeff Leger178b1e52020-10-05 12:22:23 -0400278void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
279 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600280 if (disabled[command_buffer_state]) return;
281
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700282 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600283 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
284 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400285}
286
Tony-LunarGb61514a2021-11-02 12:36:51 -0600287void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
288 if (disabled[command_buffer_state]) return;
289
290 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
291 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
292 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
293}
294
locke-lunargd556cc32019-09-17 01:21:23 -0600295void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
296 VkImageLayout srcImageLayout, VkImage dstImage,
297 VkImageLayout dstImageLayout, uint32_t regionCount,
298 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600299 if (disabled[command_buffer_state]) return;
300
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700301 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600302 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600303}
304
Jeff Leger178b1e52020-10-05 12:22:23 -0400305void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
306 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600307 if (disabled[command_buffer_state]) return;
308
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700309 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600310 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
311 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400312}
313
Tony-LunarG562fc102021-11-12 13:58:35 -0700314void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
315 const VkResolveImageInfo2 *pResolveImageInfo) {
316 if (disabled[command_buffer_state]) return;
317
318 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
319 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
320 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
321}
322
locke-lunargd556cc32019-09-17 01:21:23 -0600323void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
324 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
325 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600326 if (disabled[command_buffer_state]) return;
327
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700328 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600329 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600330}
331
Jeff Leger178b1e52020-10-05 12:22:23 -0400332void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
333 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600334 if (disabled[command_buffer_state]) return;
335
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700336 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600337 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
338 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400339}
340
Tony-LunarG542ae912021-11-04 16:06:44 -0600341void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
342 if (disabled[command_buffer_state]) return;
343
344 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
345 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
346 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
347}
348
locke-lunargd556cc32019-09-17 01:21:23 -0600349void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
350 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
351 VkResult result) {
352 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600353
Aitor Camacho3294edd2022-05-16 22:34:19 +0200354 std::shared_ptr<BUFFER_STATE> buffer_state;
355 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) {
356 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) {
357 buffer_state = std::make_shared<BUFFER_STATE_SPARSE<true>>(this, *pBuffer, pCreateInfo);
358 } else {
359 buffer_state = std::make_shared<BUFFER_STATE_SPARSE<false>>(this, *pBuffer, pCreateInfo);
360 }
361 } else {
362 buffer_state = std::make_shared<BUFFER_STATE_LINEAR>(this, *pBuffer, pCreateInfo);
363 }
locke-lunargd556cc32019-09-17 01:21:23 -0600364
James Rumble2f6e7bb2021-07-13 15:21:20 +0100365 if (pCreateInfo) {
366 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700367 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700368 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100369 // address is used for GPU-AV and ray tracing buffer validation
370 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700371 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100372 }
373 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600374 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600375}
376
377void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
378 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
379 VkResult result) {
380 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600381
Jeremy Gebben9f537102021-10-05 16:37:12 -0600382 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600383
ziga-lunarg7b29e662022-08-29 02:32:48 +0200384 VkFormatFeatureFlags2KHR buffer_features;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200385 if (has_format_feature2) {
386 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
387 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
388 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
389 buffer_features = fmt_props_3.bufferFeatures;
390 } else {
391 VkFormatProperties format_properties;
392 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
393 buffer_features = format_properties.bufferFeatures;
394 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600395
ziga-lunarg7b29e662022-08-29 02:32:48 +0200396 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600397}
398
399void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
400 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
401 VkResult result) {
402 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600403 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700404
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200405 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600406 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700407 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600408 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700409 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200410 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
411 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
412 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700413 }
414
locke-lunarg9939d4b2020-10-26 20:11:08 -0600415 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600416 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600417 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700418 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600419 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700420 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600421 image_format_info.type = image_state->createInfo.imageType;
422 image_format_info.format = image_state->createInfo.format;
423 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600424 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
425 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600426 image_format_info.flags = image_state->createInfo.flags;
427
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600428 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600429
430 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
431 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600432
Jeremy Gebben082a9832021-10-28 13:40:11 -0600433 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600434}
435
436void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
437 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600438 if (disabled[command_buffer_state]) return;
439
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700440 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600441 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600442}
443
Jeff Leger178b1e52020-10-05 12:22:23 -0400444void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600445 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600446 if (disabled[command_buffer_state]) return;
447
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700448 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600449 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
450 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400451}
452
Tony-LunarGef035472021-11-02 10:23:33 -0600453void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
454 if (disabled[command_buffer_state]) return;
455
456 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
457 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
458 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
459}
460
locke-lunargd556cc32019-09-17 01:21:23 -0600461void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
462 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600463 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600464}
465
466void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700467 auto buffer_state = Get<BUFFER_STATE>(buffer);
468 if (buffer_state) {
469 WriteLockGuard guard(buffer_address_lock_);
470 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
471 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600472 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600473}
474
475void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
476 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600477 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600478}
479
480void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
481 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600482 if (disabled[command_buffer_state]) return;
483
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700484 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600485 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600486}
487
488void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
489 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
490 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600491 if (disabled[command_buffer_state]) return;
492
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700493 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600494
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600495 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600496}
497
Jeff Leger178b1e52020-10-05 12:22:23 -0400498void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
499 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600500 if (disabled[command_buffer_state]) return;
501
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700502 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600503 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
504 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400505}
506
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700507void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
508 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
509 if (disabled[command_buffer_state]) return;
510
511 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
512 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
513 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
514}
515
locke-lunargd556cc32019-09-17 01:21:23 -0600516void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
517 VkImageLayout dstImageLayout, uint32_t regionCount,
518 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600519 if (disabled[command_buffer_state]) return;
520
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700521 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600522 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600523}
524
Jeff Leger178b1e52020-10-05 12:22:23 -0400525void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
526 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600527 if (disabled[command_buffer_state]) return;
528
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700529 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600530 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
531 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400532}
533
Tony Barbour845d29b2021-11-09 11:43:14 -0700534void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
535 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
536 if (disabled[command_buffer_state]) return;
537
538 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
539 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
540 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
541}
542
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700543// Gets union of all features defined by Potential Format Features
544// except, does not handle the external format case for AHB as that only can be used for sampled images
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200545VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
546 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700547
548 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200549 if (has_format_feature2) {
550 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200551 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
552 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200553 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100554
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200555 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100556
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200557 format_features |= fmt_props_3.linearTilingFeatures;
558 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100559
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200560 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
561 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
562 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
563 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
564 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100565
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200566 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
567 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
568 }
569 }
570 } else {
571 VkFormatProperties format_properties;
572 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
573 format_features |= format_properties.linearTilingFeatures;
574 format_features |= format_properties.optimalTilingFeatures;
575
576 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
577 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
578 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
579
580 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
581
582 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
583 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
584 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
585 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
586
587 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
588 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
589 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700590 }
591 }
592 }
593
594 return format_features;
595}
596
locke-lunargd556cc32019-09-17 01:21:23 -0600597void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
598 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
599 VkResult result) {
600 if (VK_SUCCESS != result) return;
601
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600602 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600603 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
604 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600605 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600606
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600607 device_state->instance_state = this;
608 // Save local link to this device's physical device state
609 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
610 // finish setup in the object representing the device
611 device_state->CreateDevice(pCreateInfo);
612}
613
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -0300614std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags, const VkQueueFamilyProperties &queueFamilyProperties) {
615 return std::make_shared<QUEUE_STATE>(q, index, flags, queueFamilyProperties);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -0600616}
617
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600618void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600619 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
620 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700621 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600622 if (features2) {
623 enabled_features_found = &(features2->features);
624 }
625 }
626
locke-lunargd556cc32019-09-17 01:21:23 -0600627 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600628 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600629 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600630 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600631 }
632
Tony-LunarG273f32f2021-09-28 08:56:30 -0600633 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
634 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600635 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600636 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600637 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600638 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
639 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600640 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600641 }
642
643 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
644 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600645 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
646 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600647 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
648 }
649
650 const auto *pipeline_creation_cache_control_features =
651 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
652 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600653 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600654 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
655 }
656
657 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
658 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600659 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600660 }
661
662 const auto *demote_to_helper_invocation_features =
663 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
664 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600665 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600666 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
667 }
668
669 const auto *terminate_invocation_features =
670 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
671 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600672 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600673 }
674
675 const auto *subgroup_size_control_features =
676 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
677 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600678 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
679 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600680 }
681
682 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
683 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600684 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600685 }
686
687 const auto *texture_compression_astchdr_features =
688 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
689 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600690 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600691 }
692
693 const auto *initialize_workgroup_memory_features =
694 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
695 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600696 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600697 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
698 }
699
700 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
701 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600702 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600703 }
704
705 const auto *shader_integer_dot_product_features =
706 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
707 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600708 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600709 }
710
711 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
712 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600713 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600714 }
715 }
716
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700717 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700718 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600719 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700720 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700721 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.drawIndirectCount = VK_FALSE;
723 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
724 enabled_features.core12.descriptorIndexing = VK_FALSE;
725 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
726 enabled_features.core12.shaderOutputLayer = VK_FALSE;
727 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
728 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700729
730 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700731
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700732 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700733 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
735 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700736 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600737 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700738 }
739
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700740 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700741 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
743 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700744 }
745
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700746 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700747 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600748 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700749 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600750 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700751 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600752 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700753 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700755 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600756 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700757 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600758 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700759 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700761 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600762 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700763 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600764 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700765 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600768 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700769 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600770 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700771 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600772 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700773 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600774 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700775 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600776 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700777 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600778 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700779 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600780 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700781 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600782 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
783 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700784 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600785 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700786 }
787
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700788 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700789 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600790 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 }
792
793 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700794 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700795 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600796 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700797 }
798
799 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700800 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700801 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600802 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700803 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700804 }
805
806 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700807 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700808 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600809 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700810 }
811
812 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700813 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700814 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600815 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700816 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700817 }
818
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700819 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700820 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600821 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700822 }
823
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700824 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700825 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600826 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700827 }
828
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700829 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700830 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600831 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
832 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
833 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700834 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800835
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700836 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800837 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600838 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
839 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800840 }
841
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700842 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800843 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600844 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
845 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
846 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800847 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
848 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 }
850
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700851 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700852 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600853 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700854 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700855 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700856
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700857 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700858 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600859 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
860 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700861 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600862 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
863 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700864 }
865
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700866 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700867 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600868 enabled_features.core11.multiview = multiview_features->multiview;
869 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
870 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700871 }
872
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700873 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700874 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600875 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
876 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700877 }
878
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700879 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700880 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600881 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700882 }
883
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700884 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700885 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600886 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700887 }
888
889 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700890 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700891 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600892 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700893 }
894 }
895
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700896 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600897 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600898 physical_device_count = device_group_ci->physicalDeviceCount;
arno-lunarg2cfacb32022-09-07 15:34:01 +0200899 if (physical_device_count == 0) {
900 physical_device_count =
901 1; // see https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDeviceGroupDeviceCreateInfo.html
902 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600903 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600904 } else {
arno-lunarg2cfacb32022-09-07 15:34:01 +0200905 device_group_create_info = LvlInitStruct<VkDeviceGroupDeviceCreateInfo>();
906 device_group_create_info.physicalDeviceCount = 1; // see previous VkDeviceGroupDeviceCreateInfo link
907 device_group_create_info.pPhysicalDevices = &physical_device;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600908 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600909 }
locke-lunargd556cc32019-09-17 01:21:23 -0600910
sfricke-samsung828e59d2021-08-22 23:20:49 -0700911 // Features from other extensions passesd in create info
912 {
913 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
914 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600915 enabled_features.exclusive_scissor_features = *exclusive_scissor_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 *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
919 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600920 enabled_features.shading_rate_image_features = *shading_rate_image_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 *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
924 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600925 enabled_features.mesh_shader_features = *mesh_shader_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 *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
929 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600930 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700931 }
locke-lunargd556cc32019-09-17 01:21:23 -0600932
sfricke-samsung828e59d2021-08-22 23:20:49 -0700933 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
934 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600935 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700937
sfricke-samsung828e59d2021-08-22 23:20:49 -0700938 const auto *buffer_device_address_ext_features =
939 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
940 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600941 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_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 *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
945 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600946 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700947 }
locke-lunargd556cc32019-09-17 01:21:23 -0600948
sfricke-samsung828e59d2021-08-22 23:20:49 -0700949 const auto *compute_shader_derivatives_features =
950 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
951 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600952 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700953 }
locke-lunargd556cc32019-09-17 01:21:23 -0600954
sfricke-samsung828e59d2021-08-22 23:20:49 -0700955 const auto *fragment_shader_barycentric_features =
956 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
957 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600958 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700959 }
locke-lunargd556cc32019-09-17 01:21:23 -0600960
sfricke-samsung828e59d2021-08-22 23:20:49 -0700961 const auto *shader_image_footprint_features =
962 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
963 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600964 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700965 }
locke-lunargd556cc32019-09-17 01:21:23 -0600966
sfricke-samsung828e59d2021-08-22 23:20:49 -0700967 const auto *fragment_shader_interlock_features =
968 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
969 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600970 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700971 }
locke-lunargd556cc32019-09-17 01:21:23 -0600972
sfricke-samsung828e59d2021-08-22 23:20:49 -0700973 const auto *texel_buffer_alignment_features =
974 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
975 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600976 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700977 }
locke-lunargd556cc32019-09-17 01:21:23 -0600978
sfricke-samsung828e59d2021-08-22 23:20:49 -0700979 const auto *pipeline_exe_props_features =
980 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
981 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600982 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700983 }
locke-lunargd556cc32019-09-17 01:21:23 -0600984
sfricke-samsung828e59d2021-08-22 23:20:49 -0700985 const auto *dedicated_allocation_image_aliasing_features =
986 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
987 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600988 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
992 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600993 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700994 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100995
sfricke-samsung828e59d2021-08-22 23:20:49 -0700996 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
997 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600998 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 }
Tobias Hector782bcde2019-11-28 16:19:42 +00001000
sfricke-samsung828e59d2021-08-22 23:20:49 -07001001 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
1002 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001003 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001004 }
sfricke-samsungcead0802020-01-30 22:20:10 -08001005
sfricke-samsung828e59d2021-08-22 23:20:49 -07001006 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
1007 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001008 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001009 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001010
sfricke-samsung828e59d2021-08-22 23:20:49 -07001011 const auto *ray_tracing_pipeline_features =
1012 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
1013 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001014 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001015 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001016
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 const auto *ray_tracing_acceleration_structure_features =
1018 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
1019 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001020 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001022
sfricke-samsung828e59d2021-08-22 23:20:49 -07001023 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
1024 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001025 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001026 }
Jeff Bolz165818a2020-05-08 11:19:03 -05001027
sfricke-samsung828e59d2021-08-22 23:20:49 -07001028 const auto *fragment_density_map_features =
1029 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1030 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001031 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001032 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001033
sfricke-samsung828e59d2021-08-22 23:20:49 -07001034 const auto *fragment_density_map_features2 =
1035 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1036 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001037 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001038 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001039
Agarwal, Arpit78509112022-02-17 15:29:05 -07001040 const auto *fragment_density_map_offset_features =
1041 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1042 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001043 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001044 }
1045
sfricke-samsung828e59d2021-08-22 23:20:49 -07001046 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1047 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001048 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001050
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1052 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001053 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001054 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001055
sfricke-samsung828e59d2021-08-22 23:20:49 -07001056 const auto *fragment_shading_rate_features =
1057 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1058 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001059 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001060 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001061
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001062 const auto *fragment_shading_rate_enums_features =
1063 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1064 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001065 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001066 }
1067
sfricke-samsung828e59d2021-08-22 23:20:49 -07001068 const auto *extended_dynamic_state_features =
1069 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1070 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001071 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001072 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001073
sfricke-samsung828e59d2021-08-22 23:20:49 -07001074 const auto *extended_dynamic_state2_features =
1075 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1076 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001077 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1081 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001082 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001083 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001084
sfricke-samsung828e59d2021-08-22 23:20:49 -07001085 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1086 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001087 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001088 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001089
sfricke-samsung828e59d2021-08-22 23:20:49 -07001090 const auto *shader_integer_functions2_features =
1091 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1092 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001093 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_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_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1097 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001098 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_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_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1102 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001103 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001104 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001105
sfricke-samsung828e59d2021-08-22 23:20:49 -07001106 const auto *shader_image_atomic_int64_features =
1107 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1108 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001109 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001111
sfricke-samsung828e59d2021-08-22 23:20:49 -07001112 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1113 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001114 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001115 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001116
sfricke-samsung828e59d2021-08-22 23:20:49 -07001117 const auto *conditional_rendering_features =
1118 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1119 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001120 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001121 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001122
sfricke-samsung828e59d2021-08-22 23:20:49 -07001123 const auto *workgroup_memory_explicit_layout_features =
1124 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1125 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001126 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001128
sfricke-samsung828e59d2021-08-22 23:20:49 -07001129 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1130 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001131 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001132 }
Locke Linf3873542021-04-26 11:25:10 -06001133
sfricke-samsung828e59d2021-08-22 23:20:49 -07001134 const auto *vertex_input_dynamic_state_features =
1135 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1136 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001137 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001138 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001139
sfricke-samsung828e59d2021-08-22 23:20:49 -07001140 const auto *inherited_viewport_scissor_features =
1141 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1142 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001143 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001144 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001145
sfricke-samsung828e59d2021-08-22 23:20:49 -07001146 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1147 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001148 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001149 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001150
sfricke-samsung828e59d2021-08-22 23:20:49 -07001151 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1152 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001153 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001154 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001155
sfricke-samsung828e59d2021-08-22 23:20:49 -07001156 const auto *shader_atomic_float2_features =
1157 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1158 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001159 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001160 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001161
sfricke-samsung828e59d2021-08-22 23:20:49 -07001162 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1163 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001164 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001165 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001166
sfricke-samsung828e59d2021-08-22 23:20:49 -07001167 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1168 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001169 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001170 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001171
1172 const auto *ray_tracing_motion_blur_features =
1173 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1174 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001175 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001176 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001177
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001178 const auto *primitive_topology_list_restart_features =
1179 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1180 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001181 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001182 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001183
ziga-lunarge1988962021-09-16 13:32:34 +02001184 const auto *zero_initialize_work_group_memory_features =
1185 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1186 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001187 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001188 }
1189
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001190 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1191 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001192 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001193 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001194
Tony-LunarG69604c42021-11-22 16:00:12 -07001195 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1196 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001197 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001198 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001199
1200 const auto *primitives_generated_query_features =
1201 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1202 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001203 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001204 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001205
1206 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1207 if (image_2d_view_of_3d_features) {
1208 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1209 }
Nathaniel Cesario553ab032022-04-14 10:56:22 -06001210
1211 const auto graphics_pipeline_library_features =
1212 LvlFindInChain<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(pCreateInfo->pNext);
1213 if (graphics_pipeline_library_features) {
1214 enabled_features.graphics_pipeline_library_features = *graphics_pipeline_library_features;
1215 }
ziga-lunarge25f5f02022-04-16 15:07:35 +02001216
1217 const auto shader_subgroup_uniform_control_flow_features =
1218 LvlFindInChain<VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR>(pCreateInfo->pNext);
1219 if (shader_subgroup_uniform_control_flow_features) {
1220 enabled_features.shader_subgroup_uniform_control_flow_features = *shader_subgroup_uniform_control_flow_features;
1221 }
Mike Schuchardt840f1252022-05-11 11:31:25 -07001222
sjfrickee9b39372022-05-22 13:02:17 +09001223 const auto ray_tracing_maintenance1_features =
Mike Schuchardt840f1252022-05-11 11:31:25 -07001224 LvlFindInChain<VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR>(pCreateInfo->pNext);
1225 if (ray_tracing_maintenance1_features) {
1226 enabled_features.ray_tracing_maintenance1_features= *ray_tracing_maintenance1_features;
1227 }
sjfricke52defd42022-08-08 16:37:46 +09001228
Tony-LunarG206b1bb2022-06-13 12:20:05 -06001229 const auto non_seamless_cube_map_features =
1230 LvlFindInChain<VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT>(pCreateInfo->pNext);
1231 if (non_seamless_cube_map_features) {
1232 enabled_features.non_seamless_cube_map_features = *non_seamless_cube_map_features;
1233 }
Tony-LunarG7384f7e2022-07-05 14:20:42 -06001234
1235 const auto multisampled_render_to_single_sampled_features =
1236 LvlFindInChain<VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT>(pCreateInfo->pNext);
1237 if (multisampled_render_to_single_sampled_features) {
1238 enabled_features.multisampled_render_to_single_sampled_features = *multisampled_render_to_single_sampled_features;
1239 }
Tony-LunarG1672d002022-08-03 14:35:34 -06001240
1241 const auto shader_module_identifier_features =
1242 LvlFindInChain<VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT>(pCreateInfo->pNext);
1243 if (shader_module_identifier_features) {
1244 enabled_features.shader_module_identifier_features = *shader_module_identifier_features;
1245 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001246 }
1247
locke-lunargd556cc32019-09-17 01:21:23 -06001248 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001249 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1250 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001251
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001252 {
1253 uint32_t n_props = 0;
1254 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001255 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001256 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001257 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001258
1259 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001260 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001261 }
1262
1263 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1264 // a path to grab that information from the physical device. This
1265 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1266 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001267 has_format_feature2 =
1268 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1269 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001270 }
1271
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001272 const auto &dev_ext = device_extensions;
1273 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001274
Tony-LunarG273f32f2021-09-28 08:56:30 -06001275 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1276 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001277 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1278 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001279 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001280 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001281 } else {
1282 // VkPhysicalDeviceVulkan11Properties
1283 //
1284 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1285
1286 if (dev_ext.vk_khr_multiview) {
1287 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001288 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1289 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1290 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001291 }
1292
1293 if (dev_ext.vk_khr_maintenance3) {
1294 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001295 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1296 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1297 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001298 }
1299
1300 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001301 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001302 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1303 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1304 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001305 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001307 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1308 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1309 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1310 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001311
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001312 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001313 }
1314
1315 // VkPhysicalDeviceVulkan12Properties
1316 //
1317 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1318
1319 if (dev_ext.vk_ext_descriptor_indexing) {
1320 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001321 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1322 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001323 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001324 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001325 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001326 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001327 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001328 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001329 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001330 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001331 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001332 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001333 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001334 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1335 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1336 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001337 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001338 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001339 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001340 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001341 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001342 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001343 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001344 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001345 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001346 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001347 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001348 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001349 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001350 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001351 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001352 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001353 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001354 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001355 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001356 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001357 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001358 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001359 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001360 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001361 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001362 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001363 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001364 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001365 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1366 }
1367
1368 if (dev_ext.vk_khr_depth_stencil_resolve) {
1369 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001370 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1371 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1372 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1373 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1374 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001375 }
1376
1377 if (dev_ext.vk_khr_timeline_semaphore) {
1378 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001379 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1380 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001381 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1382 }
1383
1384 if (dev_ext.vk_ext_sampler_filter_minmax) {
1385 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001386 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1387 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001388 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001389 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001390 }
1391
1392 if (dev_ext.vk_khr_shader_float_controls) {
1393 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001394 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1395 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1396 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1397 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001398 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001399 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001400 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001401 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001402 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001403 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1404 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1405 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1406 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1407 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1408 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1409 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1410 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1411 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1412 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1413 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1414 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001415 }
locke-lunargd556cc32019-09-17 01:21:23 -06001416 }
1417
sfricke-samsung828e59d2021-08-22 23:20:49 -07001418 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001419 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1420 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1421 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1422 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1423 &phys_dev_props->inline_uniform_block_props);
1424 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1425 &phys_dev_props->vtx_attrib_divisor_props);
1426 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1427 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1428 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1429 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1430 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1431 &phys_dev_props->texel_buffer_alignment_props);
1432 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1433 &phys_dev_props->fragment_density_map_props);
1434 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1435 &phys_dev_props->fragment_density_map2_props);
1436 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001437 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001438 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1439 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1440 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1441 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1442 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1443 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1444 &phys_dev_props->fragment_shading_rate_props);
1445 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1446 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1447 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1448 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1449 &phys_dev_props->blend_operation_advanced_props);
1450 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1451 &phys_dev_props->conservative_rasterization_props);
1452 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1453 &phys_dev_props->subgroup_size_control_props);
ziga-lunarge25f5f02022-04-16 15:07:35 +02001454 if (api_version >= VK_API_VERSION_1_1) {
1455 GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_properties);
1456 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001457
sfricke-samsung45996a42021-09-16 13:45:27 -07001458 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001459 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001460 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1461 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001462 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1463 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001464
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001465 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001466 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1467 NULL);
1468 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001469
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001470 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1471 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001472 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001473
locke-lunargd556cc32019-09-17 01:21:23 -06001474 // Store queue family data
1475 if (pCreateInfo->pQueueCreateInfos != nullptr) {
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001476 uint32_t num_queue_families = 0;
1477 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
1478 std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
1479 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
1480
locke-lunargd556cc32019-09-17 01:21:23 -06001481 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001482 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001483 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1484 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001485 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001486 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001487 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001488 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1489 VkQueue queue = VK_NULL_HANDLE;
1490 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1491 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1492 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1493 get_info.flags = queue_info.flags;
1494 get_info.queueFamilyIndex = queue_info.queue_family_index;
1495 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001496 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001497 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001498 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001499 }
1500 assert(queue != VK_NULL_HANDLE);
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001501 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags,
1502 queue_family_properties_list[queue_info.queue_family_index]));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001503 }
locke-lunargd556cc32019-09-17 01:21:23 -06001504 }
1505 }
1506}
1507
1508void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1509 if (!device) return;
1510
Jeremy Gebbend177d922021-10-28 13:42:10 -06001511 command_pool_map_.clear();
1512 assert(command_buffer_map_.empty());
1513 pipeline_map_.clear();
1514 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001515
1516 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001517 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001518 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001519 assert(descriptor_set_map_.empty());
1520 desc_template_map_.clear();
1521 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001522 // Because swapchains are associated with Surfaces, which are at instance level,
1523 // they need to be explicitly destroyed here to avoid continued references to
1524 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001525 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001526 entry.second->Destroy();
1527 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001528 swapchain_map_.clear();
1529 image_view_map_.clear();
1530 image_map_.clear();
1531 buffer_view_map_.clear();
1532 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001533 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001534 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001535}
1536
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001537void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1538 VkFence fence, VkResult result) {
1539 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001540 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001541
Jeremy Gebben57642982021-09-14 14:14:55 -06001542 uint64_t early_retire_seq = 0;
1543
1544 if (submitCount == 0) {
1545 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001546 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001547 early_retire_seq = queue_state->Submit(std::move(submission));
1548 }
locke-lunargd556cc32019-09-17 01:21:23 -06001549
1550 // Now process each individual submit
1551 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001552 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001553 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001554 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001555 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001556 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001557 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1558 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1559 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1560 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001561 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001562 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001563
locke-lunargd556cc32019-09-17 01:21:23 -06001564 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001565 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001566 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1567 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1568 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1569 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001570 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001571 }
1572
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001573 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001574 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001575
locke-lunargd556cc32019-09-17 01:21:23 -06001576 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001577 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1578 if (cb_state) {
1579 submission.AddCommandBuffer(std::move(cb_state));
1580 }
locke-lunargd556cc32019-09-17 01:21:23 -06001581 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001582 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001583 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001584 }
1585 auto submit_seq = queue_state->Submit(std::move(submission));
1586 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001587 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001588
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001589 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001590 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001591 }
1592}
1593
Tony-LunarG26fe2842021-11-16 14:07:59 -07001594void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1595 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001596 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001597 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001598 uint64_t early_retire_seq = 0;
1599 if (submitCount == 0) {
1600 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001601 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001602 early_retire_seq = queue_state->Submit(std::move(submission));
1603 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001604
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001605 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1606 CB_SUBMISSION submission;
1607 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001608 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1609 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001610 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001611 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001612 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1613 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001614 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001615 }
1616 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1617 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1618
1619 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001620 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001621 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001622 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001623 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001624 }
1625 auto submit_seq = queue_state->Submit(std::move(submission));
1626 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001627 }
locke-lunargd556cc32019-09-17 01:21:23 -06001628 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001629 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001630 }
1631}
1632
Tony-LunarG26fe2842021-11-16 14:07:59 -07001633void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1634 VkFence fence, VkResult result) {
1635 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1636}
1637
1638void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1639 VkFence fence, VkResult result) {
1640 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1641}
1642
locke-lunargd556cc32019-09-17 01:21:23 -06001643void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1644 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1645 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001646 if (VK_SUCCESS != result) {
1647 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001648 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001649 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1650 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1651 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1652
1653 layer_data::optional<DedicatedBinding> dedicated_binding;
1654
1655 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1656 if (dedicated) {
1657 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001658 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001659 assert(buffer_state);
1660 if (!buffer_state) {
1661 return;
1662 }
1663 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1664 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001665 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001666 assert(image_state);
1667 if (!image_state) {
1668 return;
1669 }
1670 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1671 }
1672 }
Rodrigo Locatti37ddb022022-03-15 17:27:42 -03001673 Add(CreateDeviceMemoryState(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap, std::move(dedicated_binding),
1674 physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001675 return;
1676}
1677
1678void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001679 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001680 if (mem_info) {
1681 fake_memory.Free(mem_info->fake_base_address);
1682 }
1683 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001684}
1685
1686void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1687 VkFence fence, VkResult result) {
1688 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001689 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001690
Jeremy Gebben57642982021-09-14 14:14:55 -06001691 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001692
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001693 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1694 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001695 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001696 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1697 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1698 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001699 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001700 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001701 if (buffer_state) {
1702 buffer_state->BindMemory(buffer_state.get(), mem_state, sparse_binding.memoryOffset,
1703 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001704 }
locke-lunargd556cc32019-09-17 01:21:23 -06001705 }
1706 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001707 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1708 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1709 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001710 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001711 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001712 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001713 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1714 // See: VUID-vkGetImageSubresourceLayout-image-01895
1715 if (!image_state->fragment_encoder) {
1716 image_state->fragment_encoder =
1717 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1718 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001719 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset,
1720 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001721 }
locke-lunargd556cc32019-09-17 01:21:23 -06001722 }
1723 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001724 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1725 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1726 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001727 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1728 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Aitor Camacho3294edd2022-05-16 22:34:19 +02001729 VkDeviceSize offset = sparse_binding.offset.z * sparse_binding.offset.y * sparse_binding.offset.x * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001730 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001731 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001732 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001733 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1734 // See: VUID-vkGetImageSubresourceLayout-image-01895
1735 if (!image_state->fragment_encoder) {
1736 image_state->fragment_encoder =
1737 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1738 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001739 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset, offset, size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001740 }
locke-lunargd556cc32019-09-17 01:21:23 -06001741 }
1742 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001743 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001744 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001745 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001746 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001747 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001748 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001749 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001750 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001751 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001752 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001753 auto submit_seq = queue_state->Submit(std::move(submission));
1754 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001755 }
1756
1757 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001758 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001759 }
1760}
1761
1762void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1763 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1764 VkResult result) {
1765 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06001766 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext), pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001767}
1768
Mike Schuchardt2df08912020-12-15 16:28:09 -08001769void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1770 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001771 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1772 if (semaphore_state) {
1773 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001774 }
1775}
1776
Mike Schuchardt2df08912020-12-15 16:28:09 -08001777void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001778 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001779 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001780 if (semaphore_state) {
1781 semaphore_state->RetireTimeline(pSignalInfo->value);
1782 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001783}
1784
locke-lunargd556cc32019-09-17 01:21:23 -06001785void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001786 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001787 if (mem_info) {
1788 mem_info->mapped_range.offset = offset;
1789 mem_info->mapped_range.size = size;
1790 mem_info->p_driver_data = *ppData;
1791 }
1792}
1793
locke-lunargd556cc32019-09-17 01:21:23 -06001794void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1795 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1796 if (VK_SUCCESS != result) return;
1797
1798 // When we know that all fences are complete we can clean/remove their CBs
1799 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1800 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001801 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001802 if (fence_state) {
1803 fence_state->Retire();
1804 }
locke-lunargd556cc32019-09-17 01:21:23 -06001805 }
1806 }
1807 // NOTE : Alternate case not handled here is when some fences have completed. In
1808 // this case for app to guarantee which fences completed it will have to call
1809 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1810}
1811
John Zulauff89de662020-04-13 18:57:34 -06001812void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1813 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001814 if (VK_SUCCESS != result) return;
1815
Jeremy Gebben15332642021-12-15 19:33:15 -07001816 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1817 // the application calls vkGetSemaphoreCounterValue() on each of them.
1818 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1819 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1820 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1821 if (semaphore_state) {
1822 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1823 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001824 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001825 }
1826}
1827
John Zulauff89de662020-04-13 18:57:34 -06001828void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1829 VkResult result) {
1830 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1831}
1832
1833void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1834 uint64_t timeout, VkResult result) {
1835 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1836}
1837
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001838void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1839 VkResult result) {
1840 if (VK_SUCCESS != result) return;
1841
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001842 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001843 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001844 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001845 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001846}
1847
1848void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1849 VkResult result) {
1850 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1851}
1852void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1853 VkResult result) {
1854 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1855}
1856
locke-lunargd556cc32019-09-17 01:21:23 -06001857void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1858 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001859 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001860 if (fence_state) {
1861 fence_state->Retire();
1862 }
locke-lunargd556cc32019-09-17 01:21:23 -06001863}
1864
Yilong Lice03a312022-01-02 02:08:35 -08001865void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1866 if (Get<QUEUE_STATE>(queue) == nullptr) {
Rodrigo Locatti7ab778d2022-03-09 18:57:15 -03001867 uint32_t num_queue_families = 0;
1868 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
1869 std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
1870 instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
1871
1872 Add(CreateQueue(queue, queue_family_index, flags, queue_family_properties_list[queue_family_index]));
Yilong Lice03a312022-01-02 02:08:35 -08001873 }
1874}
1875
1876void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1877 VkQueue *pQueue) {
1878 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1879}
1880
1881void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1882 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1883}
1884
locke-lunargd556cc32019-09-17 01:21:23 -06001885void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1886 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001887 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001888 if (queue_state) {
1889 queue_state->Retire();
1890 }
locke-lunargd556cc32019-09-17 01:21:23 -06001891}
1892
1893void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1894 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001895 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001896 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001897 }
1898}
1899
1900void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001901 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001902}
1903
1904void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1905 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001906 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001907}
1908
1909void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001910 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001911}
1912
1913void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1914 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001915 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001916}
1917
locke-lunargd556cc32019-09-17 01:21:23 -06001918void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001919 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001920 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001921 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001922 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001923 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02001924 buffer_state->BindMemory(buffer_state.get(), mem_state, memoryOffset, 0u, buffer_state->requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001925 }
locke-lunargd556cc32019-09-17 01:21:23 -06001926 }
1927}
1928
1929void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1930 VkDeviceSize memoryOffset, VkResult result) {
1931 if (VK_SUCCESS != result) return;
1932 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1933}
1934
1935void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001936 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001937 for (uint32_t i = 0; i < bindInfoCount; i++) {
1938 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1939 }
1940}
1941
1942void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001943 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001944 for (uint32_t i = 0; i < bindInfoCount; i++) {
1945 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1946 }
1947}
1948
Spencer Fricke6c127102020-04-16 06:25:20 -07001949void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001950 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001951 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001952 buffer_state->memory_requirements_checked = true;
1953 }
1954}
1955
1956void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1957 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001958 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001959}
1960
1961void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001962 const VkBufferMemoryRequirementsInfo2 *pInfo,
1963 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001964 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001965}
1966
1967void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001968 const VkBufferMemoryRequirementsInfo2 *pInfo,
1969 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001970 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001971}
1972
Spencer Fricke6c127102020-04-16 06:25:20 -07001973void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001974 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001975 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001976 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001977 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001978 if (plane_info != nullptr) {
1979 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001980 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001981 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001982 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001983 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001984 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001985 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001986 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001987 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001988 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001989 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001990 }
locke-lunargd556cc32019-09-17 01:21:23 -06001991 }
1992}
1993
1994void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1995 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001996 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001997}
1998
1999void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
2000 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002001 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002002}
2003
2004void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
2005 const VkImageMemoryRequirementsInfo2 *pInfo,
2006 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002007 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002008}
2009
locke-lunargd556cc32019-09-17 01:21:23 -06002010void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
2011 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
2012 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002013 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06002014 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002015}
2016
2017void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002018 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2019 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002020 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002021 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002022}
2023
2024void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002025 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2026 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002027 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002028 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002029}
2030
2031void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2032 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002033 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06002034}
2035
2036void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2037 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2042 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002043 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002044}
2045
2046void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2047 const VkAllocationCallbacks *pAllocator) {
2048 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002049 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002050 // Any bound cmd buffers are now invalid
2051 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002052 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2053 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2054 custom_border_color_sampler_count--;
2055 }
locke-lunargd556cc32019-09-17 01:21:23 -06002056 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06002057 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002058}
2059
2060void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2061 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002062 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002063}
2064
2065void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2066 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002067 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002068}
2069
locke-lunargd556cc32019-09-17 01:21:23 -06002070void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2071 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002072 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2073 if (pool) {
2074 pool->Free(commandBufferCount, pCommandBuffers);
2075 }
locke-lunargd556cc32019-09-17 01:21:23 -06002076}
2077
2078void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2079 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2080 VkResult result) {
2081 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002082 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002083 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06002084}
2085
2086void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2087 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2088 VkResult result) {
2089 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002090
2091 uint32_t index_count = 0, n_perf_pass = 0;
2092 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002093 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002094 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002095 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002096
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002097 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002098 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2099 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2100 switch (counter.scope) {
2101 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002102 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002103 break;
2104 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002105 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002106 break;
2107 default:
2108 break;
2109 }
2110 }
2111
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002112 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002113 }
2114
Jeremy Gebben082a9832021-10-28 13:40:11 -06002115 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 -06002116
locke-lunargd556cc32019-09-17 01:21:23 -06002117}
2118
2119void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2120 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002121 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002122}
2123
2124void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2125 VkCommandPoolResetFlags flags, VkResult result) {
2126 if (VK_SUCCESS != result) return;
2127 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002128 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2129 if (pool) {
2130 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002131 }
2132}
2133
2134void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2135 VkResult result) {
2136 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002137 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002138 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002139 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002140 }
2141 }
2142}
2143
locke-lunargd556cc32019-09-17 01:21:23 -06002144void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2145 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002146 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002147}
2148
2149void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2150 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002151 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002152}
2153
2154void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2155 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2156 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002157 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002158}
2159
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002160std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2161 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2162 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2163 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2164}
2165
locke-lunargd556cc32019-09-17 01:21:23 -06002166bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2167 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2168 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002169 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002170 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002171 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2172 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2173 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2174 cgpl_state->pipe_state.reserve(count);
2175 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002176 const auto &create_info = pCreateInfos[i];
2177 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2178 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2179
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002180 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002181 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002182 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002183 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2184 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002185 } else {
2186 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2187 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2188 if (!is_graphics_lib && !has_link_info) {
2189 skip = true;
2190 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002191 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002192 cgpl_state->pipe_state.push_back(
2193 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002194 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002195 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002196}
2197
2198void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2199 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2200 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2201 VkResult result, void *cgpl_state_data) {
2202 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2203 // This API may create pipelines regardless of the return value
2204 for (uint32_t i = 0; i < count; i++) {
2205 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002206 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002207 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002208 }
2209 }
2210 cgpl_state->pipe_state.clear();
2211}
2212
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002213std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2214 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2215 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2216}
2217
locke-lunargd556cc32019-09-17 01:21:23 -06002218bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2219 const VkComputePipelineCreateInfo *pCreateInfos,
2220 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002221 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002222 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2223 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2224 ccpl_state->pipe_state.reserve(count);
2225 for (uint32_t i = 0; i < count; i++) {
2226 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002227 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002228 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002229 }
2230 return false;
2231}
2232
2233void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2234 const VkComputePipelineCreateInfo *pCreateInfos,
2235 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2236 VkResult result, void *ccpl_state_data) {
2237 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2238
2239 // This API may create pipelines regardless of the return value
2240 for (uint32_t i = 0; i < count; i++) {
2241 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002242 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002243 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002244 }
2245 }
2246 ccpl_state->pipe_state.clear();
2247}
2248
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002249std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2250 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2251 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2252}
2253
locke-lunargd556cc32019-09-17 01:21:23 -06002254bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2255 uint32_t count,
2256 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2257 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002258 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002259 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2260 crtpl_state->pipe_state.reserve(count);
2261 for (uint32_t i = 0; i < count; i++) {
2262 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002263 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002264 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002265 }
2266 return false;
2267}
2268
2269void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2270 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2271 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2272 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2273 // This API may create pipelines regardless of the return value
2274 for (uint32_t i = 0; i < count; i++) {
2275 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002276 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002277 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002278 }
2279 }
2280 crtpl_state->pipe_state.clear();
2281}
2282
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002283std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2284 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2285 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2286}
2287
sourav parmarcd5fb182020-07-17 12:58:44 -07002288bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2289 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002290 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2291 const VkAllocationCallbacks *pAllocator,
2292 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002293 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002294 crtpl_state->pipe_state.reserve(count);
2295 for (uint32_t i = 0; i < count; i++) {
2296 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002297 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002298 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002299 }
2300 return false;
2301}
2302
sourav parmarcd5fb182020-07-17 12:58:44 -07002303void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2304 VkPipelineCache pipelineCache, uint32_t count,
2305 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2306 const VkAllocationCallbacks *pAllocator,
2307 VkPipeline *pPipelines, VkResult result,
2308 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002309 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002310 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002311 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002312
2313 if (!operation_is_deferred) {
2314 for (uint32_t i = 0; i < count; i++) {
2315 if (pPipelines[i] != VK_NULL_HANDLE) {
2316 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2317 Add(std::move((crtpl_state->pipe_state)[i]));
2318 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002319 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002320 } else {
2321 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2322 if (wrap_handles) {
2323 deferredOperation = layer_data->Unwrap(deferredOperation);
2324 }
2325 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2326 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2327 if (find_res->first) {
2328 cleanup_fn = std::move(find_res->second);
2329 }
2330 auto &pipeline_states = crtpl_state->pipe_state;
2331 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2332 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2333 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2334 pipeline_states[i]->SetHandle(pipelines[i]);
2335 this->Add(std::move(pipeline_states[i]));
2336 }
2337 });
2338 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002339 }
2340 crtpl_state->pipe_state.clear();
2341}
2342
locke-lunargd556cc32019-09-17 01:21:23 -06002343void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2344 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2345 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002346 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002347 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2348 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002349 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002350 }
locke-lunargd556cc32019-09-17 01:21:23 -06002351}
2352
2353void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2354 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2355 const VkAllocationCallbacks *pAllocator,
2356 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2357 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002358 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002359}
2360
locke-lunargd556cc32019-09-17 01:21:23 -06002361void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2362 const VkAllocationCallbacks *pAllocator,
2363 VkPipelineLayout *pPipelineLayout, VkResult result) {
2364 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002365 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002366}
2367
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002368std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2369 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2370 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2371}
2372
locke-lunargd556cc32019-09-17 01:21:23 -06002373void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2374 const VkAllocationCallbacks *pAllocator,
2375 VkDescriptorPool *pDescriptorPool, VkResult result) {
2376 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002377 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002378}
2379
2380void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2381 VkDescriptorPoolResetFlags flags, VkResult result) {
2382 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002383 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2384 if (pool) {
2385 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002386 }
locke-lunargd556cc32019-09-17 01:21:23 -06002387}
2388
2389bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2390 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002391 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002392 // Always update common data
2393 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2394 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2395 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2396
2397 return false;
2398}
2399
2400// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2401void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2402 VkDescriptorSet *pDescriptorSets, VkResult result,
2403 void *ads_state_data) {
2404 if (VK_SUCCESS != result) return;
2405 // All the updates are contained in a single cvdescriptorset function
2406 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2407 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002408 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2409 if (pool_state) {
2410 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2411 }
locke-lunargd556cc32019-09-17 01:21:23 -06002412}
2413
2414void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2415 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002416 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2417 if (pool_state) {
2418 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002419 }
2420}
2421
2422void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2423 const VkWriteDescriptorSet *pDescriptorWrites,
2424 uint32_t descriptorCopyCount,
2425 const VkCopyDescriptorSet *pDescriptorCopies) {
2426 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2427 pDescriptorCopies);
2428}
2429
2430void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002431 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002432 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002433 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002434 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002435 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002436 }
2437}
2438
locke-lunargd556cc32019-09-17 01:21:23 -06002439void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2440 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002441 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002442 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002443
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002444 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002445}
2446
2447void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002448 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002449 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002450
2451 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002452}
2453
2454void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2455 VkResult result) {
2456 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002457 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2458 if (cb_state) {
2459 cb_state->Reset();
2460 }
locke-lunargd556cc32019-09-17 01:21:23 -06002461 }
2462}
2463
2464CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2465 // initially assume everything is static state
2466 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2467
2468 if (ds) {
2469 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002470 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002471 }
2472 }
locke-lunargd556cc32019-09-17 01:21:23 -06002473 return flags;
2474}
2475
2476// Validation cache:
2477// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002478
2479void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2480 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002481 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002482 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002483 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002484
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002485 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002486 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002487 const auto *raster_state = pipe_state->RasterizationState();
2488 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002489 const auto *viewport_state = pipe_state->ViewportState();
2490 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002491 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002492 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002493 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002494 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002495
2496 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002497 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2498 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002499 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002500 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002501 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002502 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002503 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002504 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002505
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002506 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002507 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2508 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2509 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002510 if (!has_dynamic_viewport_count) {
2511 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002512 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002513 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2514 // should become = ~uint32_t(0) if the other interpretation is correct.
2515 }
2516 }
2517 if (!has_dynamic_scissor_count) {
2518 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002519 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002520 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2521 // should become = ~uint32_t(0) if the other interpretation is correct.
2522 }
2523 }
locke-lunargd556cc32019-09-17 01:21:23 -06002524 }
Nathaniel Cesario62f03592022-07-11 09:19:20 -06002525 cb_state->BindPipeline(ConvertToLvlBindPoint(pipelineBindPoint), pipe_state.get());
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002526 if (!disabled[command_buffer_state]) {
2527 cb_state->AddChild(pipe_state);
2528 }
locke-lunargd556cc32019-09-17 01:21:23 -06002529}
2530
2531void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2532 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002533 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002534 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002535 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2536 cb_state->viewportMask |= bits;
2537 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002538
2539 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2540 for (size_t i = 0; i < viewportCount; ++i) {
2541 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2542 }
locke-lunargd556cc32019-09-17 01:21:23 -06002543}
2544
2545void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2546 uint32_t exclusiveScissorCount,
2547 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002548 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002549 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002550 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2551 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002552}
2553
2554void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2555 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002556 if (disabled[command_buffer_state]) return;
2557
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002558 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002559 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002560
2561 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002562 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002563 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002564 }
2565}
2566
2567void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2568 uint32_t viewportCount,
2569 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002570 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002571 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002572 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2573 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002574}
2575
2576void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2577 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2578 const VkAllocationCallbacks *pAllocator,
2579 VkAccelerationStructureNV *pAccelerationStructure,
2580 VkResult result) {
2581 if (VK_SUCCESS != result) return;
Aitor Camacho3294edd2022-05-16 22:34:19 +02002582 std::shared_ptr<ACCELERATION_STRUCTURE_STATE> state =
2583 std::make_shared<ACCELERATION_STRUCTURE_STATE_LINEAR>(device, *pAccelerationStructure, pCreateInfo);
2584 Add(std::move(state));
locke-lunargd556cc32019-09-17 01:21:23 -06002585}
2586
Jeff Bolz95176d02020-04-01 00:36:16 -05002587void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2588 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2589 const VkAllocationCallbacks *pAllocator,
2590 VkAccelerationStructureKHR *pAccelerationStructure,
2591 VkResult result) {
2592 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002593 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2594 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002595}
2596
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002597void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2598 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2599 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2600 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2601 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002602 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002603 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002604 dst_as_state->Build(&pInfos[i], true, *ppBuildRangeInfos);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002605 }
2606 }
2607}
2608
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002609// helper method for device side acceleration structure builds
2610void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2611 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2612 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2613 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002614 dst_as_state->Build(&info, false, nullptr);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002615 }
2616 if (disabled[command_buffer_state]) {
2617 return;
2618 }
2619 if (dst_as_state) {
2620 cb_state.AddChild(dst_as_state);
2621 }
2622 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2623 if (src_as_state) {
2624 cb_state.AddChild(src_as_state);
2625 }
2626 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2627 if (scratch_buffer) {
2628 cb_state.AddChild(scratch_buffer);
2629 }
2630
2631 for (uint32_t i = 0; i < info.geometryCount; i++) {
2632 // only one of pGeometries and ppGeometries can be non-null
2633 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2634 switch (geom.geometryType) {
2635 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2636 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2637 if (vertex_buffer) {
2638 cb_state.AddChild(vertex_buffer);
2639 }
2640 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2641 if (index_buffer) {
2642 cb_state.AddChild(index_buffer);
2643 }
2644 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2645 if (transform_buffer) {
2646 cb_state.AddChild(transform_buffer);
2647 }
2648 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2649 if (motion_data) {
2650 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2651 if (motion_buffer) {
2652 cb_state.AddChild(motion_buffer);
2653 }
2654 }
2655 } break;
2656 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2657 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2658 if (data_buffer) {
2659 cb_state.AddChild(data_buffer);
2660 }
2661 } break;
2662 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2663 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2664 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2665 // easily ensure that's true.
2666 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2667 if (data_buffer) {
2668 cb_state.AddChild(data_buffer);
2669 }
2670 } break;
2671 default:
2672 break;
2673 }
2674 }
2675}
2676
sourav parmarcd5fb182020-07-17 12:58:44 -07002677void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2678 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2679 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002680 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002681 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002682 return;
2683 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002684 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002685 for (uint32_t i = 0; i < infoCount; i++) {
2686 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002687 }
sjfricke52defd42022-08-08 16:37:46 +09002688 cb_state->has_build_as_cmd = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07002689}
2690
2691void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2692 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2693 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2694 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002695 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2696 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002697 return;
2698 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002699 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002700 for (uint32_t i = 0; i < infoCount; i++) {
2701 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002702 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002703 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2704 if (indirect_buffer) {
2705 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002706 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002707 }
2708 }
sjfricke52defd42022-08-08 16:37:46 +09002709 cb_state->has_build_as_cmd = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07002710}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002711
locke-lunargd556cc32019-09-17 01:21:23 -06002712void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002713 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002714 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002715 if (as_state != nullptr) {
2716 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002717 as_state->memory_requirements_checked = true;
2718 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002719 as_state->build_scratch_memory_requirements_checked = true;
2720 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002721 as_state->update_scratch_memory_requirements_checked = true;
2722 }
2723 }
2724}
2725
sourav parmarcd5fb182020-07-17 12:58:44 -07002726void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2727 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002728 if (VK_SUCCESS != result) return;
2729 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002730 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002731
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002732 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002733 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002734 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002735 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002736 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02002737 as_state->BindMemory(as_state.get(), mem_state, info.memoryOffset, 0u, as_state->memory_requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002738 }
locke-lunargd556cc32019-09-17 01:21:23 -06002739
2740 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002741 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002742 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002743 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2744 }
2745 }
2746 }
2747}
2748
2749void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2750 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2751 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002752 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2753 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002754 return;
2755 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002756 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002757
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002758 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002759 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002760 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002761 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002762 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002763 }
locke-lunargd556cc32019-09-17 01:21:23 -06002764 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002765 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002766 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002767 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002768 cb_state->AddChild(src_as_state);
2769 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002770 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2771 if (instance_buffer) {
2772 cb_state->AddChild(instance_buffer);
2773 }
2774 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2775 if (scratch_buffer) {
2776 cb_state->AddChild(scratch_buffer);
2777 }
2778
2779 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2780 const auto& geom = pInfo->pGeometries[i];
2781
2782 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2783 if (vertex_buffer) {
2784 cb_state->AddChild(vertex_buffer);
2785 }
2786 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2787 if (index_buffer) {
2788 cb_state->AddChild(index_buffer);
2789 }
2790 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2791 if (transform_buffer) {
2792 cb_state->AddChild(transform_buffer);
2793 }
2794
2795 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2796 if (aabb_buffer) {
2797 cb_state->AddChild(aabb_buffer);
2798 }
2799 }
2800
locke-lunargd556cc32019-09-17 01:21:23 -06002801 }
sjfricke52defd42022-08-08 16:37:46 +09002802 cb_state->has_build_as_cmd = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002803}
2804
2805void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2806 VkAccelerationStructureNV dst,
2807 VkAccelerationStructureNV src,
2808 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002809 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002810 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002811 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2812 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002813 if (!disabled[command_buffer_state]) {
2814 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2815 }
locke-lunargd556cc32019-09-17 01:21:23 -06002816 if (dst_as_state != nullptr && src_as_state != nullptr) {
2817 dst_as_state->built = true;
2818 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002819 }
2820 }
2821}
2822
Jeff Bolz95176d02020-04-01 00:36:16 -05002823void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2824 VkAccelerationStructureKHR accelerationStructure,
2825 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002826 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002827}
2828
Jeff Bolz95176d02020-04-01 00:36:16 -05002829void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2830 VkAccelerationStructureNV accelerationStructure,
2831 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002832 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002833}
2834
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002835void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2836 uint32_t viewportCount,
2837 const VkViewportWScalingNV *pViewportWScalings) {
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_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002840}
2841
locke-lunargd556cc32019-09-17 01:21:23 -06002842void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002843 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002844 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002845}
2846
2847void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2848 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002849 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002850 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002851}
2852
2853void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2854 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002855 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002856 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002857}
2858
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002859void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2860 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002861 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002862 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002863 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2864 cb_state->scissorMask |= bits;
2865 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002866}
2867
locke-lunargd556cc32019-09-17 01:21:23 -06002868void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002869 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002870 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002871}
2872
2873void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2874 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002875 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002876 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002877}
2878
2879void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2880 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002881 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002882 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002883}
2884
2885void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2886 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002887 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002888 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002889}
2890
2891void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2892 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002893 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002894 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002895}
2896
locke-lunargd556cc32019-09-17 01:21:23 -06002897// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2898void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2899 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2900 uint32_t firstSet, uint32_t setCount,
2901 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2902 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002903 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002904 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002905 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002906 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002907
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002908 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2909 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002910}
2911
locke-lunargd556cc32019-09-17 01:21:23 -06002912void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2913 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2914 uint32_t set, uint32_t descriptorWriteCount,
2915 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002916 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002917 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002918 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002919}
2920
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002921void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2922 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2923 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002924 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2925 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002926 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002927 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2928 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002929
2930 auto &push_constant_data = cb_state->push_constant_data;
2931 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2932 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002933 cb_state->push_constant_pipeline_layout_set = layout;
2934
2935 auto flags = stageFlags;
2936 uint32_t bit_shift = 0;
2937 while (flags) {
2938 if (flags & 1) {
2939 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2940 const auto it = cb_state->push_constant_data_update.find(flag);
2941
2942 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002943 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002944 }
2945 }
2946 flags = flags >> 1;
2947 ++bit_shift;
2948 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002949 }
2950}
2951
locke-lunargd556cc32019-09-17 01:21:23 -06002952void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2953 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002954 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002955
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002956 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002957 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002958 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002959 cb_state->index_buffer_binding.offset = offset;
2960 cb_state->index_buffer_binding.index_type = indexType;
2961 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002962 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002963 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002964 }
locke-lunargd556cc32019-09-17 01:21:23 -06002965}
2966
2967void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2968 uint32_t bindingCount, const VkBuffer *pBuffers,
2969 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002970 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002971 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002972
2973 uint32_t end = firstBinding + bindingCount;
2974 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2975 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2976 }
2977
2978 for (uint32_t i = 0; i < bindingCount; ++i) {
2979 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002980 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002981 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002982 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2983 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002984 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002985 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002986 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002987 }
locke-lunargd556cc32019-09-17 01:21:23 -06002988 }
2989}
2990
2991void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2992 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002993 if (disabled[command_buffer_state]) return;
2994
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002995 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002996 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002997}
2998
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002999void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3000 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003001 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003002 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003003}
3004
3005void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3006 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003007 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003008 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3009
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003010 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
3011 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003012}
3013
Tony-LunarGc43525f2021-11-15 16:12:38 -07003014void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3015 const VkDependencyInfo* pDependencyInfo) {
3016 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3017 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3018
3019 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
3020 cb_state->RecordBarriers(*pDependencyInfo);
3021}
3022
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003023void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3024 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003025 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003026 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003027}
3028
3029void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3030 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003031 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003032 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003033}
3034
Tony-LunarGa2662db2021-11-16 07:26:24 -07003035void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3036 VkPipelineStageFlags2 stageMask) {
3037 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3038 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
3039}
3040
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003041void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3042 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
3043 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3044 uint32_t bufferMemoryBarrierCount,
3045 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3046 uint32_t imageMemoryBarrierCount,
3047 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003048 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3049 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003050 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3051 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003052}
3053
3054void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3055 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003056 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06003057 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003058 const auto &dep_info = pDependencyInfos[i];
3059 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3060 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
3061 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06003062 }
3063}
3064
Tony-LunarG1364cf52021-11-17 16:10:11 -07003065void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3066 const VkDependencyInfo *pDependencyInfos) {
3067 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3068 for (uint32_t i = 0; i < eventCount; i++) {
3069 const auto &dep_info = pDependencyInfos[i];
3070 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3071 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
3072 cb_state->RecordBarriers(dep_info);
3073 }
3074}
3075
Jeremy Gebben79649152021-06-22 14:46:24 -06003076void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3077 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3078 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3079 uint32_t bufferMemoryBarrierCount,
3080 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3081 uint32_t imageMemoryBarrierCount,
3082 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003083 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003084 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3085 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3086 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003087}
3088
3089void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3090 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003091 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003092 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3093 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003094}
3095
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07003096void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
3097 const VkDependencyInfo *pDependencyInfo) {
3098 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3099 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
3100 cb_state->RecordBarriers(*pDependencyInfo);
3101}
3102
locke-lunargd556cc32019-09-17 01:21:23 -06003103void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3104 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003105 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003106 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02003107
3108 uint32_t num_queries = 1;
3109 // If render pass instance has multiview enabled, query uses N consecutive query indices
3110 if (cb_state->activeRenderPass) {
3111 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
3112 num_queries = std::max(num_queries, bits);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003113 }
ziga-lunarg9ad42712022-08-21 03:01:29 +02003114 for (uint32_t i = 0; i < num_queries; ++i) {
3115 QueryObject query = {queryPool, slot};
3116 cb_state->RecordCmd(CMD_BEGINQUERY);
3117 if (!disabled[query_validation]) {
3118 cb_state->BeginQuery(query);
3119 }
3120 if (!disabled[command_buffer_state]) {
3121 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
3122 cb_state->AddChild(pool_state);
3123 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003124 }
locke-lunargd556cc32019-09-17 01:21:23 -06003125}
3126
3127void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003128 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003129 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02003130 uint32_t num_queries = 1;
3131 // If render pass instance has multiview enabled, query uses N consecutive query indices
3132 if (cb_state->activeRenderPass) {
3133 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
3134 num_queries = std::max(num_queries, bits);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003135 }
ziga-lunarg9ad42712022-08-21 03:01:29 +02003136
3137 for (uint32_t i = 0; i < num_queries; ++i) {
3138 QueryObject query_obj = {queryPool, slot + i};
3139 cb_state->RecordCmd(CMD_ENDQUERY);
3140 if (!disabled[query_validation]) {
3141 cb_state->EndQuery(query_obj);
3142 }
3143 if (!disabled[command_buffer_state]) {
3144 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
3145 cb_state->AddChild(pool_state);
3146 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003147 }
locke-lunargd556cc32019-09-17 01:21:23 -06003148}
3149
3150void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3151 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003152 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003153 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003154
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003155 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003156 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003157
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003158 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003159 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003160 cb_state->AddChild(pool_state);
3161 }
locke-lunargd556cc32019-09-17 01:21:23 -06003162}
3163
3164void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3165 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3166 VkDeviceSize dstOffset, VkDeviceSize stride,
3167 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003168 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3169
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003170 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003171 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003172 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003173 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003174 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003175 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003176}
3177
3178void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3179 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003180 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003181 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003182}
3183
3184void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3185 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3186 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003187 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003188 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003189}
3190
Tony-LunarGde9936b2021-11-17 15:34:11 -07003191void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3192 VkQueryPool queryPool, uint32_t slot) {
3193 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3194 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3195}
3196
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003197void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3198 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3199 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3200 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003201 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003202 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003203 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003204 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003205 cb_state->AddChild(pool_state);
3206 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003207 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003208}
3209
locke-lunargd556cc32019-09-17 01:21:23 -06003210void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3211 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3212 VkResult result) {
3213 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003214
Jeremy Gebben88f58142021-06-01 10:07:52 -06003215 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003216 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003217 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003218
locke-lunargd556cc32019-09-17 01:21:23 -06003219 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003220 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003221 }
3222 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003223
Jeremy Gebben9f537102021-10-05 16:37:12 -06003224 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003225 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003226}
3227
locke-lunargd556cc32019-09-17 01:21:23 -06003228void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3229 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3230 VkResult result) {
3231 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003232 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003233}
3234
Mike Schuchardt2df08912020-12-15 16:28:09 -08003235void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003236 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3237 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003238 if (VK_SUCCESS != result) return;
3239
Jeremy Gebben082a9832021-10-28 13:40:11 -06003240 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003241}
3242
Mike Schuchardt2df08912020-12-15 16:28:09 -08003243void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003244 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3245 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003246 if (VK_SUCCESS != result) return;
3247
Jeremy Gebben082a9832021-10-28 13:40:11 -06003248 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003249}
3250
locke-lunargd556cc32019-09-17 01:21:23 -06003251void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3252 const VkRenderPassBeginInfo *pRenderPassBegin,
3253 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003254 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003255 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003256}
3257
3258void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3259 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003260 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003261 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003262 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003263}
3264
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003265void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3266 uint32_t counterBufferCount,
3267 const VkBuffer *pCounterBuffers,
3268 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003269 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003270
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003271 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003272 cb_state->transform_feedback_active = true;
3273}
3274
3275void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3276 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3277 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003278 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003279
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003280 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003281 cb_state->transform_feedback_active = false;
3282}
3283
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003284void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3285 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003286 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003287
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003288 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003289 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003290 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3291 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003292}
3293
3294void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003295 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003296
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003297 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003298 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003299 cb_state->conditional_rendering_inside_render_pass = false;
3300 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003301}
3302
amhagana448ea52021-11-02 14:09:14 -04003303void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003304 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003305 cb_state->activeRenderPass = nullptr;
3306}
3307
3308void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3309 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003310 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003311 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3312}
3313
Tony-LunarG40b33882021-12-02 12:40:11 -07003314void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3315 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3316 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3317}
3318
amhagana448ea52021-11-02 14:09:14 -04003319void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3320 RecordCmdEndRenderingRenderPassState(commandBuffer);
3321}
3322
Tony-LunarG40b33882021-12-02 12:40:11 -07003323void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3324 RecordCmdEndRenderingRenderPassState(commandBuffer);
3325}
3326
Tony-LunarG977448c2019-12-02 14:52:02 -07003327void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3328 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003329 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003330 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003331 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003332}
3333
locke-lunargd556cc32019-09-17 01:21:23 -06003334void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003335 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003336 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003337}
3338
3339void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003340 const VkSubpassBeginInfo *pSubpassBeginInfo,
3341 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003342 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003343 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003344}
3345
Tony-LunarG977448c2019-12-02 14:52:02 -07003346void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003347 const VkSubpassBeginInfo *pSubpassBeginInfo,
3348 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003349 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003350 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003351}
3352
3353void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003354 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003355 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003356}
3357
3358void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003359 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003360 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003361 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003362}
3363
Tony-LunarG977448c2019-12-02 14:52:02 -07003364void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003365 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003366 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003367 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003368}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003369
locke-lunargd556cc32019-09-17 01:21:23 -06003370void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3371 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003372 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003373
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003374 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003375}
3376
3377void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3378 VkFlags flags, void **ppData, VkResult result) {
3379 if (VK_SUCCESS != result) return;
3380 RecordMappedMemory(mem, offset, size, ppData);
3381}
3382
3383void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003384 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003385 if (mem_info) {
3386 mem_info->mapped_range = MemRange();
3387 mem_info->p_driver_data = nullptr;
3388 }
3389}
3390
3391void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003392 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003393 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003394 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3395 // See: VUID-vkGetImageSubresourceLayout-image-01895
3396 image_state->fragment_encoder =
3397 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003398 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003399 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003400 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003401 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003402 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003403
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003404 if (!swapchain_image.fake_base_address) {
3405 auto size = image_state->fragment_encoder->TotalSize();
3406 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003407 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003408 // All images bound to this swapchain and index are aliases
3409 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003410 }
3411 } else {
3412 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003413 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003414 if (mem_info) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02003415 VkDeviceSize plane_index = 0u;
3416 if (image_state->disjoint && image_state->IsExternalAHB() == false) {
3417 auto plane_info = LvlFindInChain<VkBindImagePlaneMemoryInfo>(bindInfo.pNext);
3418 const VkImageAspectFlagBits aspect = plane_info->planeAspect;
3419 switch (aspect) {
3420 case VK_IMAGE_ASPECT_PLANE_0_BIT:
3421 plane_index = 0;
3422 break;
3423 case VK_IMAGE_ASPECT_PLANE_1_BIT:
3424 plane_index = 1;
3425 break;
3426 case VK_IMAGE_ASPECT_PLANE_2_BIT:
3427 plane_index = 2;
3428 break;
3429 default:
3430 assert(false); // parameter validation should have caught this
3431 break;
3432 }
3433 }
3434 image_state->BindMemory(
3435 image_state.get(), mem_info, bindInfo.memoryOffset, plane_index,
3436 image_state->requirements[static_cast<decltype(image_state->requirements)::size_type>(plane_index)].size);
locke-lunargd556cc32019-09-17 01:21:23 -06003437 }
locke-lunargd556cc32019-09-17 01:21:23 -06003438 }
locke-lunargd556cc32019-09-17 01:21:23 -06003439 }
3440}
3441
3442void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3443 VkDeviceSize memoryOffset, VkResult result) {
3444 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003445 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003446 bind_info.image = image;
3447 bind_info.memory = mem;
3448 bind_info.memoryOffset = memoryOffset;
3449 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003450}
3451
3452void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003453 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003454 if (VK_SUCCESS != result) return;
3455 for (uint32_t i = 0; i < bindInfoCount; i++) {
3456 UpdateBindImageMemoryState(pBindInfos[i]);
3457 }
3458}
3459
3460void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003461 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003462 if (VK_SUCCESS != result) return;
3463 for (uint32_t i = 0; i < bindInfoCount; i++) {
3464 UpdateBindImageMemoryState(pBindInfos[i]);
3465 }
3466}
3467
3468void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003469 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003470 if (event_state) {
3471 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3472 }
locke-lunargd556cc32019-09-17 01:21:23 -06003473}
3474
3475void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3476 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3477 VkResult result) {
3478 if (VK_SUCCESS != result) return;
3479 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3480 pImportSemaphoreFdInfo->flags);
3481}
3482
3483void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003484 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003485 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003486 if (semaphore_state) {
3487 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003488 }
3489}
3490
3491#ifdef VK_USE_PLATFORM_WIN32_KHR
3492void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3493 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3494 if (VK_SUCCESS != result) return;
3495 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3496 pImportSemaphoreWin32HandleInfo->flags);
3497}
3498
3499void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3500 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3501 HANDLE *pHandle, VkResult result) {
3502 if (VK_SUCCESS != result) return;
3503 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3504}
3505
3506void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3507 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3508 if (VK_SUCCESS != result) return;
3509 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3510 pImportFenceWin32HandleInfo->flags);
3511}
3512
3513void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3514 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3515 HANDLE *pHandle, VkResult result) {
3516 if (VK_SUCCESS != result) return;
3517 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3518}
3519#endif
3520
3521void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3522 VkResult result) {
3523 if (VK_SUCCESS != result) return;
3524 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3525}
3526
Mike Schuchardt2df08912020-12-15 16:28:09 -08003527void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3528 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003529 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003530
3531 if (fence_node) {
3532 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003533 }
3534}
3535
3536void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3537 VkResult result) {
3538 if (VK_SUCCESS != result) return;
3539 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3540}
3541
Mike Schuchardt2df08912020-12-15 16:28:09 -08003542void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003543 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003544 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003545 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003546 }
3547}
3548
3549void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3550 VkResult result) {
3551 if (VK_SUCCESS != result) return;
3552 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3553}
3554
3555void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3556 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3557 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06003558 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003559}
3560
3561void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003562 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003563 SWAPCHAIN_NODE *old_swapchain_state) {
3564 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003565 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003566 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003567 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003568 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3569 surface_state->AddParent(swapchain.get());
3570 surface_state->swapchain = swapchain.get();
3571 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003572 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003573 } else {
3574 surface_state->swapchain = nullptr;
3575 }
3576 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003577 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003578 if (old_swapchain_state) {
3579 old_swapchain_state->retired = true;
3580 }
3581 return;
3582}
3583
3584void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3585 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3586 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003587 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003588 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003589 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003590}
3591
3592void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3593 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003594 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003595}
3596
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003597void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3598 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3599 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3600 VkResult result) {
3601 if (VK_SUCCESS != result) return;
3602 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003603 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003604}
3605
locke-lunargd556cc32019-09-17 01:21:23 -06003606void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003607 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003608 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003609 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3610 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3611 if (semaphore_state) {
3612 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003613 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003614 }
3615
3616 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3617 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3618 // 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
3619 // confused itself just as much.
3620 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3621 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3622 // Mark the image as having been released to the WSI
3623 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3624 if (swapchain_data) {
3625 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3626 if (present_id_info) {
3627 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3628 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3629 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003630 }
3631 }
locke-lunargd556cc32019-09-17 01:21:23 -06003632 }
locke-lunargd556cc32019-09-17 01:21:23 -06003633}
3634
3635void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3636 const VkSwapchainCreateInfoKHR *pCreateInfos,
3637 const VkAllocationCallbacks *pAllocator,
3638 VkSwapchainKHR *pSwapchains, VkResult result) {
3639 if (pCreateInfos) {
3640 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003641 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003642 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003643 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3644 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003645 }
3646 }
3647}
3648
3649void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3650 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003651 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003652 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003653 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3654 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003655 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003656 }
3657
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003658 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003659 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003660 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3661 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003662 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003663 }
3664
3665 // Mark the image as acquired.
3666 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3667 if (swapchain_data) {
3668 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003669 }
3670}
3671
3672void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3673 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3674 VkResult result) {
3675 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3676 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3677}
3678
3679void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3680 uint32_t *pImageIndex, VkResult result) {
3681 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3682 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3683 pAcquireInfo->fence, pImageIndex);
3684}
3685
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003686std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3687 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3688}
3689
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003690void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3691 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3692 VkResult result) {
3693 if (result != VK_SUCCESS) {
3694 return;
3695 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003696 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003697 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003698 // this can fail if the allocator fails
3699 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3700 if (result != VK_SUCCESS) {
3701 return;
3702 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003703 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003704 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3705 if (result != VK_SUCCESS) {
3706 return;
3707 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003708
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003709 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003710 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003711 }
Tony-LunarGffb5b522022-06-15 15:49:27 -06003712
3713#ifdef VK_USE_PLATFORM_METAL_EXT
3714 auto export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(pCreateInfo->pNext);
3715 while (export_metal_object_info) {
3716 export_metal_flags.push_back(export_metal_object_info->exportObjectType);
3717 export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(export_metal_object_info->pNext);
3718 }
3719#endif // VK_USE_PLATFORM_METAL_EXT
locke-lunargd556cc32019-09-17 01:21:23 -06003720}
3721
Tony-LunarGffb5b522022-06-15 15:49:27 -06003722
locke-lunargd556cc32019-09-17 01:21:23 -06003723// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003724static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003725 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003726}
3727
3728void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3729 uint32_t *pQueueFamilyPropertyCount,
3730 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003731 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3732 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003733 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003734}
3735
3736void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003737 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003738 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3739 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003740 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003741}
3742
3743void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003744 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003745 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3746 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003747 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003748}
3749void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3750 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003751 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003752}
3753
Jeremy Gebben082a9832021-10-28 13:40:11 -06003754void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003755
3756void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3757 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3758 const VkAllocationCallbacks *pAllocator,
3759 VkSurfaceKHR *pSurface, VkResult result) {
3760 if (VK_SUCCESS != result) return;
3761 RecordVulkanSurface(pSurface);
3762}
3763
3764#ifdef VK_USE_PLATFORM_ANDROID_KHR
3765void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3766 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3767 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3768 VkResult result) {
3769 if (VK_SUCCESS != result) return;
3770 RecordVulkanSurface(pSurface);
3771}
3772#endif // VK_USE_PLATFORM_ANDROID_KHR
3773
3774#ifdef VK_USE_PLATFORM_IOS_MVK
3775void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3776 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3777 VkResult result) {
3778 if (VK_SUCCESS != result) return;
3779 RecordVulkanSurface(pSurface);
3780}
3781#endif // VK_USE_PLATFORM_IOS_MVK
3782
3783#ifdef VK_USE_PLATFORM_MACOS_MVK
3784void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3785 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3786 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3787 VkResult result) {
3788 if (VK_SUCCESS != result) return;
3789 RecordVulkanSurface(pSurface);
3790}
3791#endif // VK_USE_PLATFORM_MACOS_MVK
3792
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003793#ifdef VK_USE_PLATFORM_METAL_EXT
3794void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3795 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3796 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3797 VkResult result) {
3798 if (VK_SUCCESS != result) return;
3799 RecordVulkanSurface(pSurface);
3800}
3801#endif // VK_USE_PLATFORM_METAL_EXT
3802
locke-lunargd556cc32019-09-17 01:21:23 -06003803#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3804void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3805 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3806 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3807 VkResult result) {
3808 if (VK_SUCCESS != result) return;
3809 RecordVulkanSurface(pSurface);
3810}
3811#endif // VK_USE_PLATFORM_WAYLAND_KHR
3812
3813#ifdef VK_USE_PLATFORM_WIN32_KHR
3814void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3815 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3816 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3817 VkResult result) {
3818 if (VK_SUCCESS != result) return;
3819 RecordVulkanSurface(pSurface);
3820}
3821#endif // VK_USE_PLATFORM_WIN32_KHR
3822
3823#ifdef VK_USE_PLATFORM_XCB_KHR
3824void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3825 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3826 VkResult result) {
3827 if (VK_SUCCESS != result) return;
3828 RecordVulkanSurface(pSurface);
3829}
3830#endif // VK_USE_PLATFORM_XCB_KHR
3831
3832#ifdef VK_USE_PLATFORM_XLIB_KHR
3833void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3834 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3835 VkResult result) {
3836 if (VK_SUCCESS != result) return;
3837 RecordVulkanSurface(pSurface);
3838}
3839#endif // VK_USE_PLATFORM_XLIB_KHR
3840
Niklas Haas8b84af12020-04-19 22:20:11 +02003841void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3842 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3843 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3844 VkResult result) {
3845 if (VK_SUCCESS != result) return;
3846 RecordVulkanSurface(pSurface);
3847}
3848
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003849void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3850 VkSurfaceKHR surface,
3851 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3852 VkResult result) {
3853 if (VK_SUCCESS != result) return;
3854 auto surface_state = Get<SURFACE_STATE>(surface);
3855 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3856}
3857
3858void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3859 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3860 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3861 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003862
3863 if (pSurfaceInfo->surface) {
3864 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3865 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3866 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3867 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3868 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3869 assert(pd_state);
3870 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3871 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003872}
3873
3874void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3875 VkSurfaceKHR surface,
3876 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3877 VkResult result) {
3878 auto surface_state = Get<SURFACE_STATE>(surface);
3879 VkSurfaceCapabilitiesKHR caps{
3880 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3881 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3882 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3883 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3884 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3885 };
3886 surface_state->SetCapabilities(physicalDevice, caps);
3887}
3888
locke-lunargd556cc32019-09-17 01:21:23 -06003889void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3890 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3891 VkBool32 *pSupported, VkResult result) {
3892 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003893 auto surface_state = Get<SURFACE_STATE>(surface);
3894 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3895}
3896
3897void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3898 VkSurfaceKHR surface,
3899 uint32_t *pPresentModeCount,
3900 VkPresentModeKHR *pPresentModes,
3901 VkResult result) {
3902 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3903
3904 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003905 if (surface) {
3906 auto surface_state = Get<SURFACE_STATE>(surface);
3907 surface_state->SetPresentModes(physicalDevice,
3908 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3909 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3910 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3911 assert(pd_state);
3912 pd_state->surfaceless_query_state.present_modes =
3913 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3914 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003915 }
3916}
3917
3918void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3919 uint32_t *pSurfaceFormatCount,
3920 VkSurfaceFormatKHR *pSurfaceFormats,
3921 VkResult result) {
3922 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3923
3924 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003925 if (surface) {
3926 auto surface_state = Get<SURFACE_STATE>(surface);
3927 surface_state->SetFormats(physicalDevice,
3928 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3929 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3930 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3931 assert(pd_state);
3932 pd_state->surfaceless_query_state.formats =
3933 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3934 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003935 }
3936}
3937
3938void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3939 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3940 uint32_t *pSurfaceFormatCount,
3941 VkSurfaceFormat2KHR *pSurfaceFormats,
3942 VkResult result) {
3943 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3944
3945 if (pSurfaceFormats) {
3946 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003947 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3948 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3949 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003950 if (pSurfaceInfo->surface) {
3951 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3952 surface_state->SetFormats(physicalDevice, std::move(fmts));
3953 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3954 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3955 assert(pd_state);
3956 pd_state->surfaceless_query_state.formats = std::move(fmts);
3957 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003958 }
locke-lunargd556cc32019-09-17 01:21:23 -06003959}
3960
locke-lunargd556cc32019-09-17 01:21:23 -06003961void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3962 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003963 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003964 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003965 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3966}
3967
3968void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003969 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003970 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003971 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3972}
3973
3974void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3975 const VkDebugUtilsLabelEXT *pLabelInfo) {
3976 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3977
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003978 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003979 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3980 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003981 cb_state->debug_label = LoggingLabel(pLabelInfo);
3982}
3983
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003984void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3985 uint32_t queueFamilyIndex,
3986 uint32_t *pCounterCount,
3987 VkPerformanceCounterKHR *pCounters) {
3988 if (NULL == pCounters) return;
3989
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003990 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3991 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003992
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003993 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3994 queue_family_counters->counters.resize(*pCounterCount);
3995 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003996
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003997 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003998}
3999
4000void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
4001 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
4002 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
4003 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4004 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
4005}
4006
4007void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
4008 VkResult result) {
4009 if (result == VK_SUCCESS) performance_lock_acquired = true;
4010}
4011
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004012void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
4013 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06004014 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004015 cmd_buffer.second->performance_lock_released = true;
4016 }
4017}
4018
locke-lunargd556cc32019-09-17 01:21:23 -06004019void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004020 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004021 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004022 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004023}
4024
4025void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004026 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004027 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004028 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004029}
4030
Mike Schuchardt2df08912020-12-15 16:28:09 -08004031void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4032 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004033 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06004034}
4035
Mike Schuchardt2df08912020-12-15 16:28:09 -08004036void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
4037 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
4038 const VkAllocationCallbacks *pAllocator,
4039 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
4040 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004041 if (VK_SUCCESS != result) return;
4042 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4043}
4044
4045void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08004046 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4047 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004048 if (VK_SUCCESS != result) return;
4049 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4050}
4051
4052void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004053 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004054 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004055 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
4056 assert(template_state);
4057 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06004058 // TODO: Record template push descriptor updates
4059 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004060 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06004061 }
4062 }
4063}
4064
4065void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
4066 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4067 const void *pData) {
4068 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4069}
4070
4071void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004072 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004073 const void *pData) {
4074 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4075}
4076
Mike Schuchardt2df08912020-12-15 16:28:09 -08004077void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
4078 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4079 VkPipelineLayout layout, uint32_t set,
4080 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004081 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004082
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004083 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07004084 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004085 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004086 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06004087 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004088 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004089 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06004090 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004091 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06004092 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004093 static_cast<uint32_t>(decoded_template.desc_writes.size()),
4094 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06004095 }
4096}
4097
4098void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
4099 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004100 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06004101 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004102 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004103 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06004104 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004105 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004106 }
4107}
4108
4109void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
4110 uint32_t *pPropertyCount,
4111 VkDisplayPlanePropertiesKHR *pProperties,
4112 VkResult result) {
4113 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4114 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4115}
4116
4117void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
4118 uint32_t *pPropertyCount,
4119 VkDisplayPlaneProperties2KHR *pProperties,
4120 VkResult result) {
4121 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4122 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4123}
4124
4125void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4126 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004127 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02004128 uint32_t num_queries = 1;
4129 // If render pass instance has multiview enabled, query uses N consecutive query indices
4130 if (cb_state->activeRenderPass) {
4131 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
4132 num_queries = std::max(num_queries, bits);
4133 }
4134
4135 for (uint32_t i = 0; i < num_queries; ++i) {
4136 QueryObject query_obj = {queryPool, query, index + i};
4137 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
4138 cb_state->BeginQuery(query_obj);
4139 }
locke-lunargd556cc32019-09-17 01:21:23 -06004140}
4141
4142void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4143 uint32_t query, uint32_t index) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004144 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg9ad42712022-08-21 03:01:29 +02004145 uint32_t num_queries = 1;
4146 // If render pass instance has multiview enabled, query uses N consecutive query indices
4147 if (cb_state->activeRenderPass) {
4148 uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
4149 num_queries = std::max(num_queries, bits);
4150 }
4151
4152 for (uint32_t i = 0; i < num_queries; ++i) {
4153 QueryObject query_obj = {queryPool, query, index + i};
4154 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
4155 cb_state->EndQuery(query_obj);
4156 }
locke-lunargd556cc32019-09-17 01:21:23 -06004157}
4158
4159void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4160 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02004161 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004162
4163 if (create_info->format != VK_FORMAT_UNDEFINED) {
4164 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07004165 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004166 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4167 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004168 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004169
Jeremy Gebben082a9832021-10-28 13:40:11 -06004170 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004171}
4172
4173void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4174 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4175 const VkAllocationCallbacks *pAllocator,
4176 VkSamplerYcbcrConversion *pYcbcrConversion,
4177 VkResult result) {
4178 if (VK_SUCCESS != result) return;
4179 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4180}
4181
4182void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4183 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4184 const VkAllocationCallbacks *pAllocator,
4185 VkSamplerYcbcrConversion *pYcbcrConversion,
4186 VkResult result) {
4187 if (VK_SUCCESS != result) return;
4188 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4189}
4190
4191void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4192 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004193 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004194}
4195
4196void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4197 VkSamplerYcbcrConversion ycbcrConversion,
4198 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004199 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004200}
4201
Tony-LunarG977448c2019-12-02 14:52:02 -07004202void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4203 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004204 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004205 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004206
4207 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004208 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004209 if (!query_pool_state) return;
4210
4211 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004212 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4213 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004214 auto query_index = firstQuery + i;
4215 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004216 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004217 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004218 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004219 }
4220 }
locke-lunargd556cc32019-09-17 01:21:23 -06004221 }
4222}
4223
Tony-LunarG977448c2019-12-02 14:52:02 -07004224void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4225 uint32_t queryCount) {
4226 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4227}
4228
4229void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4230 uint32_t queryCount) {
4231 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4232}
4233
locke-lunargd556cc32019-09-17 01:21:23 -06004234void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004235 const UPDATE_TEMPLATE_STATE *template_state,
4236 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004237 // Translate the templated update into a normal update for validation...
4238 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4239 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4240 decoded_update.desc_writes.data(), 0, NULL);
4241}
4242
4243// Update the common AllocateDescriptorSetsData
4244void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004245 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004246 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004247 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004248 if (layout) {
4249 ds_data->layout_nodes[i] = layout;
4250 // Count total descriptors required per type
4251 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4252 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004253 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4254 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004255 }
4256 }
4257 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4258 }
4259}
4260
locke-lunargd556cc32019-09-17 01:21:23 -06004261void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4262 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004263 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004264 cb_state->UpdateDrawCmd(CMD_DRAW);
locke-lunargd556cc32019-09-17 01:21:23 -06004265}
4266
Tony-LunarG745150c2021-07-02 15:07:31 -06004267void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4268 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4269 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004270 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004271 cb_state->UpdateDrawCmd(CMD_DRAWMULTIEXT);
Tony-LunarG745150c2021-07-02 15:07:31 -06004272}
4273
locke-lunargd556cc32019-09-17 01:21:23 -06004274void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4275 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4276 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004277 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004278 cb_state->UpdateDrawCmd(CMD_DRAWINDEXED);
locke-lunargd556cc32019-09-17 01:21:23 -06004279}
4280
Tony-LunarG745150c2021-07-02 15:07:31 -06004281void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4282 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4283 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4284 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004285 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004286 cb_state->UpdateDrawCmd(CMD_DRAWMULTIINDEXEDEXT);
Tony-LunarG745150c2021-07-02 15:07:31 -06004287}
4288
locke-lunargd556cc32019-09-17 01:21:23 -06004289void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4290 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004291 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004292 auto buffer_state = Get<BUFFER_STATE>(buffer);
sjfricke52defd42022-08-08 16:37:46 +09004293 cb_state->UpdateDrawCmd(CMD_DRAWINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004294 if (!disabled[command_buffer_state]) {
4295 cb_state->AddChild(buffer_state);
4296 }
locke-lunargd556cc32019-09-17 01:21:23 -06004297}
4298
4299void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4300 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004301 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004302 auto buffer_state = Get<BUFFER_STATE>(buffer);
sjfricke52defd42022-08-08 16:37:46 +09004303 cb_state->UpdateDrawCmd(CMD_DRAWINDEXEDINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004304 if (!disabled[command_buffer_state]) {
4305 cb_state->AddChild(buffer_state);
4306 }
locke-lunargd556cc32019-09-17 01:21:23 -06004307}
4308
4309void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004310 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004311 cb_state->UpdateDispatchCmd(CMD_DISPATCH);
locke-lunargd556cc32019-09-17 01:21:23 -06004312}
4313
4314void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4315 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004316 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004317 cb_state->UpdateDispatchCmd(CMD_DISPATCHINDIRECT);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004318 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004319 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004320 cb_state->AddChild(buffer_state);
4321 }
locke-lunargd556cc32019-09-17 01:21:23 -06004322}
4323
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004324void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4325 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004326 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004327 cb_state->UpdateDispatchCmd(CMD_DISPATCHBASEKHR);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004328}
4329
4330void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4331 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004332 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004333 cb_state->UpdateDispatchCmd(CMD_DISPATCHBASE);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004334}
4335
Tony-LunarG977448c2019-12-02 14:52:02 -07004336void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4337 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004338 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004339 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004340 cb_state->UpdateDrawCmd(cmd_type);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004341 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004342 auto buffer_state = Get<BUFFER_STATE>(buffer);
4343 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004344 cb_state->AddChild(buffer_state);
4345 cb_state->AddChild(count_buffer_state);
4346 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004347}
4348
locke-lunargd556cc32019-09-17 01:21:23 -06004349void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4350 VkDeviceSize offset, VkBuffer countBuffer,
4351 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4352 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004353 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004354 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004355}
4356
4357void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4358 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4359 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004360 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004361 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004362}
4363
4364void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4365 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004366 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004367 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004368 cb_state->UpdateDrawCmd(cmd_type);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004369 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004370 auto buffer_state = Get<BUFFER_STATE>(buffer);
4371 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004372 cb_state->AddChild(buffer_state);
4373 cb_state->AddChild(count_buffer_state);
4374 }
locke-lunargd556cc32019-09-17 01:21:23 -06004375}
4376
4377void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4378 VkDeviceSize offset, VkBuffer countBuffer,
4379 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4380 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004381 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004382 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004383}
4384
4385void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4386 VkDeviceSize offset, VkBuffer countBuffer,
4387 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4388 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004389 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004390 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004391}
4392
4393void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4394 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004395 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004396 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSNV);
locke-lunargd556cc32019-09-17 01:21:23 -06004397}
4398
4399void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4400 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004401 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004402 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTNV);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004403 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004404 if (!disabled[command_buffer_state] && buffer_state) {
4405 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004406 }
4407}
4408
4409void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4410 VkDeviceSize offset, VkBuffer countBuffer,
4411 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4412 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004413 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004414 cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTCOUNTNV);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004415 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004416 auto buffer_state = Get<BUFFER_STATE>(buffer);
4417 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004418 if (buffer_state) {
4419 cb_state->AddChild(buffer_state);
4420 }
4421 if (count_buffer_state) {
4422 cb_state->AddChild(count_buffer_state);
4423 }
locke-lunargd556cc32019-09-17 01:21:23 -06004424 }
4425}
4426
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004427void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4428 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4429 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4430 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4431 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4432 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4433 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004434 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004435 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSNV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004436}
4437
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004438void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4439 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4440 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4441 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4442 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4443 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004444 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004445 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSKHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004446}
4447
4448void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4449 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4450 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4451 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4452 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4453 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004454 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004455 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECTKHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004456}
4457
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004458std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4459 uint32_t unique_shader_id) const {
4460 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4461 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4462 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4463 : std::make_shared<SHADER_MODULE_STATE>();
4464}
4465
4466std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4467 uint32_t unique_shader_id,
4468 VkShaderModule handle) const {
4469 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4470 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4471 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4472 : std::make_shared<SHADER_MODULE_STATE>();
4473}
4474
sfricke-samsungf91881c2022-03-31 01:12:00 -05004475void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer,
4476 VkDeviceAddress indirectDeviceAddress) {
4477 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sjfricke52defd42022-08-08 16:37:46 +09004478 cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECT2KHR);
sfricke-samsungf91881c2022-03-31 01:12:00 -05004479}
4480
locke-lunargd556cc32019-09-17 01:21:23 -06004481void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4482 const VkAllocationCallbacks *pAllocator,
4483 VkShaderModule *pShaderModule, VkResult result,
4484 void *csm_state_data) {
4485 if (VK_SUCCESS != result) return;
4486 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4487
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004488 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004489}
4490
John Zulauf22b0fbe2019-10-15 06:26:16 -06004491void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4492 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4493 VkResult result) {
4494 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004495 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004496
4497 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4498
4499 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004500 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004501 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004502 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004503
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004504 auto format_features = GetImageFormatFeatures(
4505 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4506 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004507
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004508 auto image_state =
4509 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004510 if (!swapchain_image.fake_base_address) {
4511 auto size = image_state->fragment_encoder->TotalSize();
4512 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004513 }
4514
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004515 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004516 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004517 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004518 }
4519 }
4520
4521 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004522 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4523 }
4524}
sourav parmar35e7a002020-06-09 17:58:44 -07004525
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004526void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4527 const VkCopyAccelerationStructureInfoKHR *pInfo,
4528 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004529 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4530 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004531 if (dst_as_state != nullptr && src_as_state != nullptr) {
4532 dst_as_state->built = true;
4533 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4534 }
4535}
4536
sourav parmar35e7a002020-06-09 17:58:44 -07004537void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4538 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004539 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004540 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004541 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004542 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4543 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004544 if (dst_as_state != nullptr && src_as_state != nullptr) {
4545 dst_as_state->built = true;
4546 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004547 if (!disabled[command_buffer_state]) {
4548 cb_state->AddChild(dst_as_state);
4549 cb_state->AddChild(src_as_state);
4550 }
sourav parmar35e7a002020-06-09 17:58:44 -07004551 }
4552 }
4553}
Piers Daniell39842ee2020-07-10 16:42:33 -06004554
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004555void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4556 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4557 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4558 if (cb_state) {
4559 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4560 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4561 if (!disabled[command_buffer_state]) {
4562 cb_state->AddChild(src_as_state);
4563 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004564 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4565 if (dst_buffer) {
4566 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004567 }
4568 }
4569}
4570
4571void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4572 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4573 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4574 if (cb_state) {
4575 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4576 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004577 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4578 if (buffer_state) {
4579 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004580 }
4581 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4582 cb_state->AddChild(dst_as_state);
4583 }
4584 }
4585}
4586
Piers Daniell39842ee2020-07-10 16:42:33 -06004587void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004588 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004589 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004590}
4591
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004592void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4593 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4594 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4595}
4596
Piers Daniell39842ee2020-07-10 16:42:33 -06004597void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004598 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004599 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004600}
4601
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004602void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4603 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4604 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4605}
4606
Piers Daniell39842ee2020-07-10 16:42:33 -06004607void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4608 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004609 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004610 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004611 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004612}
4613
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004614void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4615 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004616 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004617 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4618 cb_state->primitiveTopology = primitiveTopology;
4619}
4620
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004621void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4622 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004623 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4624 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004625 uint32_t bits = (1u << viewportCount) - 1u;
4626 cb_state->viewportWithCountMask |= bits;
4627 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004628 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004629 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004630
4631 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4632 for (size_t i = 0; i < viewportCount; ++i) {
4633 cb_state->dynamicViewports[i] = pViewports[i];
4634 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004635}
4636
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004637void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4638 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004639 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004640}
4641
4642void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004643 const VkViewport *pViewports) {
4644 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004645}
4646
4647void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4648 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004649 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004650 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004651 uint32_t bits = (1u << scissorCount) - 1u;
4652 cb_state->scissorWithCountMask |= bits;
4653 cb_state->trashedScissorMask &= ~bits;
4654 cb_state->scissorWithCountCount = scissorCount;
4655 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004656}
4657
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004658void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4659 const VkRect2D *pScissors) {
4660 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4661}
4662
4663void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4664 const VkRect2D *pScissors) {
4665 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4666}
4667
4668void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4669 uint32_t bindingCount, const VkBuffer *pBuffers,
4670 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4671 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004672 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004673 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004674
4675 uint32_t end = firstBinding + bindingCount;
4676 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4677 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4678 }
4679
4680 for (uint32_t i = 0; i < bindingCount; ++i) {
4681 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004682 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004683 vertex_buffer_binding.offset = pOffsets[i];
4684 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4685 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4686 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004687 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004688 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004689 }
4690 }
4691}
4692
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004693void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4694 uint32_t bindingCount, const VkBuffer *pBuffers,
4695 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4696 const VkDeviceSize *pStrides) {
4697 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4698 CMD_BINDVERTEXBUFFERS2EXT);
4699}
4700
4701void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4702 uint32_t bindingCount, const VkBuffer *pBuffers,
4703 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4704 const VkDeviceSize *pStrides) {
4705 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4706 CMD_BINDVERTEXBUFFERS2);
4707}
4708
Piers Daniell39842ee2020-07-10 16:42:33 -06004709void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004710 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004711 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004712}
4713
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004714void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4715 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4716 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4717}
4718
Piers Daniell39842ee2020-07-10 16:42:33 -06004719void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004720 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004721 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004722}
4723
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004724void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4725 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4726 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4727}
4728
Piers Daniell39842ee2020-07-10 16:42:33 -06004729void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004730 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004731 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004732}
4733
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004734void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4735 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4736 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4737}
4738
Piers Daniell39842ee2020-07-10 16:42:33 -06004739void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4740 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004741 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004742 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004743}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004744
4745void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4746 VkBool32 depthBoundsTestEnable) {
4747 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4748 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4749}
4750
Piers Daniell39842ee2020-07-10 16:42:33 -06004751void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
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_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004754}
4755
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004756void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4757 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4758 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4759}
4760
Piers Daniell39842ee2020-07-10 16:42:33 -06004761void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4762 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4763 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004764 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004765 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004766}
locke-lunarg4189aa22020-10-21 00:23:48 -06004767
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004768void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4769 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4770 VkCompareOp compareOp) {
4771 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4772 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4773}
4774
locke-lunarg4189aa22020-10-21 00:23:48 -06004775void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4776 uint32_t discardRectangleCount,
4777 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004778 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004779 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004780}
4781
4782void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4783 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004784 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004785 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004786}
4787
4788void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4789 VkCoarseSampleOrderTypeNV sampleOrderType,
4790 uint32_t customSampleOrderCount,
4791 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
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_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004794}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004795
4796void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004797 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004798 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004799}
4800
4801void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004802 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004803 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004804}
4805
4806void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4807 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004808 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004809 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004810 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004811}
4812
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004813void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4814 VkBool32 rasterizerDiscardEnable) {
4815 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4816 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004817 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004818}
4819
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004820void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004821 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004822 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004823}
4824
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004825void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4826 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4827 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4828}
4829
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004830void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4831 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004832 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004833 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004834}
Piers Daniell924cd832021-05-18 13:48:47 -06004835
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004836void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4837 VkBool32 primitiveRestartEnable) {
4838 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4839 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4840}
4841
Piers Daniell924cd832021-05-18 13:48:47 -06004842void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4843 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4844 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4845 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004846 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004847 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4848
4849 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4850 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4851 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004852 const auto *dynamic_state = pipeline_state->DynamicState();
4853 if (dynamic_state) {
4854 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4855 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004856 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4857 break;
4858 }
4859 }
4860 }
4861 }
4862 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004863}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004864
ziga-lunarg67b7c392022-03-26 01:45:34 +01004865void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4866 const VkBool32 *pColorWriteEnables) {
4867 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4868 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4869 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4870}
4871
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004872void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004873 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004874 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004875 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004876 // address is used for GPU-AV and ray tracing buffer validation
4877 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004878 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004879 }
4880}
4881
4882void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4883 VkDeviceAddress address) {
4884 RecordGetBufferDeviceAddress(pInfo, address);
4885}
4886
4887void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4888 VkDeviceAddress address) {
4889 RecordGetBufferDeviceAddress(pInfo, address);
4890}
4891
4892void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4893 VkDeviceAddress address) {
4894 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004895}
4896
4897std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4898 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004899 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004900}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004901
4902std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4903 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004904 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004905 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4906}
Rodrigo Locatti37ddb022022-03-15 17:27:42 -03004907
4908std::shared_ptr<DEVICE_MEMORY_STATE> ValidationStateTracker::CreateDeviceMemoryState(
4909 VkDeviceMemory mem, const VkMemoryAllocateInfo *p_alloc_info, uint64_t fake_address, const VkMemoryType &memory_type,
4910 const VkMemoryHeap &memory_heap, layer_data::optional<DedicatedBinding> &&dedicated_binding, uint32_t physical_device_count) {
4911 return std::make_shared<DEVICE_MEMORY_STATE>(mem, p_alloc_info, fake_address, memory_type, memory_heap,
4912 std::move(dedicated_binding), physical_device_count);
4913}