blob: 14afab51da3f81d7fc0c7881a53a5866fc6c5f72 [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Tobias Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Dave Houlton <daveh@lunarg.com>
21 * Shannon McPherson <shannon@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
28#include "vk_enum_string_helper.h"
29#include "vk_format_utils.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33#include "vk_typemap_helper.h"
34
35#include "chassis.h"
36#include "state_tracker.h"
37#include "shader_validation.h"
Jeremy Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
sjfrickee9b39372022-05-22 13:02:17 +0900137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200138
139 // Find the image modifier
140 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
141
142 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
143 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
144 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
145
146 // Second query to have all the modifiers filled
147 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
148
149 // Look for the image modifier in the list
150 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
151 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
152 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
153 break;
154 }
155 }
156 } else {
157 format_features =
158 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
159 }
160 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
sjfrickee9b39372022-05-22 13:02:17 +0900161 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600162 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200163
sjfrickee9b39372022-05-22 13:02:17 +0900164 VkFormatProperties2 format_properties_2 = LvlInitStruct<VkFormatProperties2>();
165 VkDrmFormatModifierPropertiesListEXT drm_properties_list = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600166 format_properties_2.pNext = (void *)&drm_properties_list;
167 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
168 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
169 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
170 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
171 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200172
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600173 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
174 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
175 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
176 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200177 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200178 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600179 } else {
180 VkFormatProperties format_properties;
181 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
182 format_features =
183 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200184 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600185 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200186}
187
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700188std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
189 VkFormatFeatureFlags2KHR features) {
Aitor Camacho3294edd2022-05-16 22:34:19 +0200190 std::shared_ptr<IMAGE_STATE> state;
191
192 if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
193 if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) {
194 state = std::make_shared<IMAGE_STATE_SPARSE<true>>(this, img, pCreateInfo, features);
195 } else {
196 state = std::make_shared<IMAGE_STATE_SPARSE<false>>(this, img, pCreateInfo, features);
197 }
198 } else if (pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
199 uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
200 switch (plane_count) {
201 case 3:
202 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<3>>(this, img, pCreateInfo, features);
203 break;
204 case 2:
205 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<2>>(this, img, pCreateInfo, features);
206 break;
207 case 1:
208 state = std::make_shared<IMAGE_STATE_MULTIPLANAR<1>>(this, img, pCreateInfo, features);
209 break;
210 default:
Shahbaz Youssefi87f53002022-06-07 10:14:01 -0400211 // Not supported
212 assert(false);
Aitor Camacho3294edd2022-05-16 22:34:19 +0200213 }
214 } else {
215 state = std::make_shared<IMAGE_STATE_LINEAR>(this, img, pCreateInfo, features);
216 }
217
218 return state;
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700219}
220
221std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
222 VkSwapchainKHR swapchain, uint32_t swapchain_index,
223 VkFormatFeatureFlags2KHR features) {
Aitor Camacho3294edd2022-05-16 22:34:19 +0200224 return std::make_shared<IMAGE_STATE_NO_BINDING>(this, img, pCreateInfo, swapchain, swapchain_index, features);
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700225}
226
locke-lunargd556cc32019-09-17 01:21:23 -0600227void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
228 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
229 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200230 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700231 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600232 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600233 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600234 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200235 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
236 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
237 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600238 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700239 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600240}
241
242void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600243 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600244}
245
246void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
247 VkImageLayout imageLayout, const VkClearColorValue *pColor,
248 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600252 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600253 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600254 }
255}
256
257void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
258 VkImageLayout imageLayout,
259 const VkClearDepthStencilValue *pDepthStencil,
260 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600261 if (disabled[command_buffer_state]) return;
262
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700263 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600264 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600265 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600266 }
267}
268
269void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
270 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
271 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600272 if (disabled[command_buffer_state]) return;
273
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700274 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600275 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600276}
277
Jeff Leger178b1e52020-10-05 12:22:23 -0400278void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
279 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600280 if (disabled[command_buffer_state]) return;
281
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700282 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600283 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
284 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400285}
286
Tony-LunarGb61514a2021-11-02 12:36:51 -0600287void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
288 if (disabled[command_buffer_state]) return;
289
290 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
291 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
292 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
293}
294
locke-lunargd556cc32019-09-17 01:21:23 -0600295void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
296 VkImageLayout srcImageLayout, VkImage dstImage,
297 VkImageLayout dstImageLayout, uint32_t regionCount,
298 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600299 if (disabled[command_buffer_state]) return;
300
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700301 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600302 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600303}
304
Jeff Leger178b1e52020-10-05 12:22:23 -0400305void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
306 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600307 if (disabled[command_buffer_state]) return;
308
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700309 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600310 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
311 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400312}
313
Tony-LunarG562fc102021-11-12 13:58:35 -0700314void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
315 const VkResolveImageInfo2 *pResolveImageInfo) {
316 if (disabled[command_buffer_state]) return;
317
318 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
319 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
320 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
321}
322
locke-lunargd556cc32019-09-17 01:21:23 -0600323void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
324 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
325 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600326 if (disabled[command_buffer_state]) return;
327
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700328 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600329 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600330}
331
Jeff Leger178b1e52020-10-05 12:22:23 -0400332void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
333 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600334 if (disabled[command_buffer_state]) return;
335
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700336 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600337 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
338 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400339}
340
Tony-LunarG542ae912021-11-04 16:06:44 -0600341void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
342 if (disabled[command_buffer_state]) return;
343
344 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
345 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
346 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
347}
348
locke-lunargd556cc32019-09-17 01:21:23 -0600349void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
350 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
351 VkResult result) {
352 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600353
Aitor Camacho3294edd2022-05-16 22:34:19 +0200354 std::shared_ptr<BUFFER_STATE> buffer_state;
355 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) {
356 if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) {
357 buffer_state = std::make_shared<BUFFER_STATE_SPARSE<true>>(this, *pBuffer, pCreateInfo);
358 } else {
359 buffer_state = std::make_shared<BUFFER_STATE_SPARSE<false>>(this, *pBuffer, pCreateInfo);
360 }
361 } else {
362 buffer_state = std::make_shared<BUFFER_STATE_LINEAR>(this, *pBuffer, pCreateInfo);
363 }
locke-lunargd556cc32019-09-17 01:21:23 -0600364
James Rumble2f6e7bb2021-07-13 15:21:20 +0100365 if (pCreateInfo) {
366 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700367 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700368 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100369 // address is used for GPU-AV and ray tracing buffer validation
370 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700371 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100372 }
373 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600374 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600375}
376
377void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
378 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
379 VkResult result) {
380 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600381
Jeremy Gebben9f537102021-10-05 16:37:12 -0600382 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600383
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300384 VkFormatFeatureFlags2KHR buffer_features, image_features;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200385 if (has_format_feature2) {
386 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
387 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
388 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
389 buffer_features = fmt_props_3.bufferFeatures;
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300390 image_features = fmt_props_3.linearTilingFeatures;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200391 } else {
392 VkFormatProperties format_properties;
393 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
394 buffer_features = format_properties.bufferFeatures;
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300395 image_features = format_properties.linearTilingFeatures;
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200396 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600397
Lionel Landwerlin519100a2022-05-12 17:23:58 +0300398 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features, image_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600399}
400
401void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
402 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
403 VkResult result) {
404 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600405 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700406
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200407 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600408 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700409 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600410 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700411 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200412 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
413 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
414 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700415 }
416
locke-lunarg9939d4b2020-10-26 20:11:08 -0600417 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600418 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600419 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700420 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600421 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700422 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600423 image_format_info.type = image_state->createInfo.imageType;
424 image_format_info.format = image_state->createInfo.format;
425 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600426 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
427 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600428 image_format_info.flags = image_state->createInfo.flags;
429
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600430 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600431
432 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
433 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600434
Jeremy Gebben082a9832021-10-28 13:40:11 -0600435 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600436}
437
438void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
439 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600440 if (disabled[command_buffer_state]) return;
441
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700442 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600443 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600444}
445
Jeff Leger178b1e52020-10-05 12:22:23 -0400446void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600447 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600448 if (disabled[command_buffer_state]) return;
449
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700450 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600451 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
452 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400453}
454
Tony-LunarGef035472021-11-02 10:23:33 -0600455void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
456 if (disabled[command_buffer_state]) return;
457
458 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
459 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
460 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
461}
462
locke-lunargd556cc32019-09-17 01:21:23 -0600463void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
464 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600465 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600466}
467
468void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700469 auto buffer_state = Get<BUFFER_STATE>(buffer);
470 if (buffer_state) {
471 WriteLockGuard guard(buffer_address_lock_);
472 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
473 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600474 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600475}
476
477void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
478 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600479 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600480}
481
482void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
483 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600484 if (disabled[command_buffer_state]) return;
485
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700486 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600487 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600488}
489
490void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
491 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
492 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600493 if (disabled[command_buffer_state]) return;
494
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700495 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600496
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600497 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600498}
499
Jeff Leger178b1e52020-10-05 12:22:23 -0400500void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
501 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600502 if (disabled[command_buffer_state]) return;
503
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700504 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600505 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
506 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400507}
508
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700509void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
510 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
511 if (disabled[command_buffer_state]) return;
512
513 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
514 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
515 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
516}
517
locke-lunargd556cc32019-09-17 01:21:23 -0600518void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
519 VkImageLayout dstImageLayout, uint32_t regionCount,
520 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600521 if (disabled[command_buffer_state]) return;
522
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700523 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600524 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600525}
526
Jeff Leger178b1e52020-10-05 12:22:23 -0400527void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
528 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600529 if (disabled[command_buffer_state]) return;
530
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700531 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600532 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
533 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400534}
535
Tony Barbour845d29b2021-11-09 11:43:14 -0700536void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
537 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
538 if (disabled[command_buffer_state]) return;
539
540 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
541 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
542 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
543}
544
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700545// Gets union of all features defined by Potential Format Features
546// except, does not handle the external format case for AHB as that only can be used for sampled images
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200547VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
548 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700549
550 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200551 if (has_format_feature2) {
552 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200553 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
554 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200555 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100556
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200557 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100558
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200559 format_features |= fmt_props_3.linearTilingFeatures;
560 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100561
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200562 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
563 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
564 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
565 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
566 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100567
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200568 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
569 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
570 }
571 }
572 } else {
573 VkFormatProperties format_properties;
574 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
575 format_features |= format_properties.linearTilingFeatures;
576 format_features |= format_properties.optimalTilingFeatures;
577
578 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
579 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
580 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
581
582 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
583
584 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
585 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
586 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
587 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
588
589 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
590 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
591 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700592 }
593 }
594 }
595
596 return format_features;
597}
598
locke-lunargd556cc32019-09-17 01:21:23 -0600599void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
600 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
601 VkResult result) {
602 if (VK_SUCCESS != result) return;
603
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600604 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600605 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
606 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600607 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600608
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600609 device_state->instance_state = this;
610 // Save local link to this device's physical device state
611 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
612 // finish setup in the object representing the device
613 device_state->CreateDevice(pCreateInfo);
614}
615
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -0600616std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags) {
617 return std::make_shared<QUEUE_STATE>(q, index, flags);
618}
619
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600620void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600621 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
622 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700623 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600624 if (features2) {
625 enabled_features_found = &(features2->features);
626 }
627 }
628
locke-lunargd556cc32019-09-17 01:21:23 -0600629 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600630 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600631 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600632 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600633 }
634
Tony-LunarG273f32f2021-09-28 08:56:30 -0600635 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
636 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600637 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600638 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600639 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600640 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
641 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600642 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600643 }
644
645 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
646 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600647 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
648 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600649 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
650 }
651
652 const auto *pipeline_creation_cache_control_features =
653 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
654 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600655 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600656 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
657 }
658
659 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
660 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600661 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600662 }
663
664 const auto *demote_to_helper_invocation_features =
665 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
666 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600667 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600668 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
669 }
670
671 const auto *terminate_invocation_features =
672 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
673 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600674 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600675 }
676
677 const auto *subgroup_size_control_features =
678 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
679 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600680 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
681 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600682 }
683
684 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
685 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600686 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600687 }
688
689 const auto *texture_compression_astchdr_features =
690 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
691 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600692 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600693 }
694
695 const auto *initialize_workgroup_memory_features =
696 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
697 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600698 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600699 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
700 }
701
702 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
703 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600704 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600705 }
706
707 const auto *shader_integer_dot_product_features =
708 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
709 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600710 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600711 }
712
713 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
714 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600715 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600716 }
717 }
718
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700719 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700720 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600721 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700722 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700723 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.drawIndirectCount = VK_FALSE;
725 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
726 enabled_features.core12.descriptorIndexing = VK_FALSE;
727 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
728 enabled_features.core12.shaderOutputLayer = VK_FALSE;
729 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
730 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700731
732 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700733
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700734 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700735 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
737 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700738 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600739 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700740 }
741
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700742 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700743 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
745 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700746 }
747
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700748 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700749 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600750 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700751 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600752 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700753 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700755 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600756 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700757 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600758 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700759 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700761 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600762 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700763 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600764 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700765 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600768 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700769 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600770 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700771 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600772 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700773 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600774 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700775 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600776 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700777 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600778 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700779 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600780 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700781 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600782 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700783 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600784 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
785 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700786 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600787 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700788 }
789
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700790 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600792 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700793 }
794
795 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700796 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700797 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600798 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700799 }
800
801 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700802 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700803 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600804 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700805 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700806 }
807
808 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700809 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700810 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600811 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700812 }
813
814 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700815 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700816 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600817 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700818 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700819 }
820
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700821 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700822 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600823 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700824 }
825
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700826 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700827 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600828 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700829 }
830
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700831 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700832 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600833 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
834 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
835 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700836 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800837
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700838 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800839 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600840 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
841 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800842 }
843
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700844 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800845 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600846 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
847 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
848 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800849 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
850 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700851 }
852
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700853 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700854 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600855 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700856 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700857 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700858
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700859 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700860 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600861 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
862 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700863 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600864 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
865 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700866 }
867
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700868 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700869 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600870 enabled_features.core11.multiview = multiview_features->multiview;
871 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
872 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700873 }
874
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700875 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700876 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600877 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
878 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700879 }
880
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700881 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700882 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600883 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700884 }
885
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700886 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700887 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600888 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700889 }
890
891 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700892 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700893 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600894 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700895 }
896 }
897
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700898 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600899 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600900 physical_device_count = device_group_ci->physicalDeviceCount;
901 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600902 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600903 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600904 }
locke-lunargd556cc32019-09-17 01:21:23 -0600905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 // Features from other extensions passesd in create info
907 {
908 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
909 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600910 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700911 }
locke-lunargd556cc32019-09-17 01:21:23 -0600912
sfricke-samsung828e59d2021-08-22 23:20:49 -0700913 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
914 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600915 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
919 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600920 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700921 }
locke-lunargd556cc32019-09-17 01:21:23 -0600922
sfricke-samsung828e59d2021-08-22 23:20:49 -0700923 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
924 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600925 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700926 }
locke-lunargd556cc32019-09-17 01:21:23 -0600927
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
929 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600930 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700931 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700932
sfricke-samsung828e59d2021-08-22 23:20:49 -0700933 const auto *buffer_device_address_ext_features =
934 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
935 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600936 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700937 }
locke-lunargd556cc32019-09-17 01:21:23 -0600938
sfricke-samsung828e59d2021-08-22 23:20:49 -0700939 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
940 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600941 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 }
locke-lunargd556cc32019-09-17 01:21:23 -0600943
sfricke-samsung828e59d2021-08-22 23:20:49 -0700944 const auto *compute_shader_derivatives_features =
945 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
946 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600947 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 }
locke-lunargd556cc32019-09-17 01:21:23 -0600949
sfricke-samsung828e59d2021-08-22 23:20:49 -0700950 const auto *fragment_shader_barycentric_features =
951 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
952 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600953 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700954 }
locke-lunargd556cc32019-09-17 01:21:23 -0600955
sfricke-samsung828e59d2021-08-22 23:20:49 -0700956 const auto *shader_image_footprint_features =
957 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
958 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600959 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700960 }
locke-lunargd556cc32019-09-17 01:21:23 -0600961
sfricke-samsung828e59d2021-08-22 23:20:49 -0700962 const auto *fragment_shader_interlock_features =
963 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
964 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600965 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 }
locke-lunargd556cc32019-09-17 01:21:23 -0600967
sfricke-samsung828e59d2021-08-22 23:20:49 -0700968 const auto *texel_buffer_alignment_features =
969 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
970 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600971 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 }
locke-lunargd556cc32019-09-17 01:21:23 -0600973
sfricke-samsung828e59d2021-08-22 23:20:49 -0700974 const auto *pipeline_exe_props_features =
975 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
976 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600977 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 }
locke-lunargd556cc32019-09-17 01:21:23 -0600979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *dedicated_allocation_image_aliasing_features =
981 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
982 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600983 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700984 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500985
sfricke-samsung828e59d2021-08-22 23:20:49 -0700986 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
987 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600988 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
992 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600993 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700994 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000995
sfricke-samsung828e59d2021-08-22 23:20:49 -0700996 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
997 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600998 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 }
sfricke-samsungcead0802020-01-30 22:20:10 -08001000
sfricke-samsung828e59d2021-08-22 23:20:49 -07001001 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
1002 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001003 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001004 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001005
sfricke-samsung828e59d2021-08-22 23:20:49 -07001006 const auto *ray_tracing_pipeline_features =
1007 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
1008 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001009 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001010 }
sourav parmarcd5fb182020-07-17 12:58:44 -07001011
sfricke-samsung828e59d2021-08-22 23:20:49 -07001012 const auto *ray_tracing_acceleration_structure_features =
1013 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
1014 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001015 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001016 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001017
sfricke-samsung828e59d2021-08-22 23:20:49 -07001018 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
1019 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001020 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 }
Jeff Bolz165818a2020-05-08 11:19:03 -05001022
sfricke-samsung828e59d2021-08-22 23:20:49 -07001023 const auto *fragment_density_map_features =
1024 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1025 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001026 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001028
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 const auto *fragment_density_map_features2 =
1030 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1031 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001032 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001034
Agarwal, Arpit78509112022-02-17 15:29:05 -07001035 const auto *fragment_density_map_offset_features =
1036 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1037 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001038 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001039 }
1040
sfricke-samsung828e59d2021-08-22 23:20:49 -07001041 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1042 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001043 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001044 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001045
sfricke-samsung828e59d2021-08-22 23:20:49 -07001046 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1047 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001048 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001050
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 const auto *fragment_shading_rate_features =
1052 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1053 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001054 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001055 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001056
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001057 const auto *fragment_shading_rate_enums_features =
1058 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1059 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001060 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001061 }
1062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *extended_dynamic_state_features =
1064 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1065 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001066 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001068
sfricke-samsung828e59d2021-08-22 23:20:49 -07001069 const auto *extended_dynamic_state2_features =
1070 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1071 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001072 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001073 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001074
sfricke-samsung828e59d2021-08-22 23:20:49 -07001075 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1076 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001077 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1081 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001082 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001083 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001084
sfricke-samsung828e59d2021-08-22 23:20:49 -07001085 const auto *shader_integer_functions2_features =
1086 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1087 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001088 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001089 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001090
sfricke-samsung828e59d2021-08-22 23:20:49 -07001091 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1092 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001093 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001094 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001095
sfricke-samsung828e59d2021-08-22 23:20:49 -07001096 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1097 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001098 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001100
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 const auto *shader_image_atomic_int64_features =
1102 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1103 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001104 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001106
sfricke-samsung828e59d2021-08-22 23:20:49 -07001107 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1108 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001109 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001111
sfricke-samsung828e59d2021-08-22 23:20:49 -07001112 const auto *conditional_rendering_features =
1113 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1114 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001115 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001116 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001117
sfricke-samsung828e59d2021-08-22 23:20:49 -07001118 const auto *workgroup_memory_explicit_layout_features =
1119 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1120 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001121 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001122 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001123
sfricke-samsung828e59d2021-08-22 23:20:49 -07001124 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1125 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001126 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 }
Locke Linf3873542021-04-26 11:25:10 -06001128
sfricke-samsung828e59d2021-08-22 23:20:49 -07001129 const auto *vertex_input_dynamic_state_features =
1130 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1131 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001132 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001133 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001134
sfricke-samsung828e59d2021-08-22 23:20:49 -07001135 const auto *inherited_viewport_scissor_features =
1136 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1137 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001138 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001139 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001140
sfricke-samsung828e59d2021-08-22 23:20:49 -07001141 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1142 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001143 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001144 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001145
sfricke-samsung828e59d2021-08-22 23:20:49 -07001146 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1147 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001148 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001149 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001150
sfricke-samsung828e59d2021-08-22 23:20:49 -07001151 const auto *shader_atomic_float2_features =
1152 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1153 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001154 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001155 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001156
sfricke-samsung828e59d2021-08-22 23:20:49 -07001157 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1158 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001159 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001160 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001161
sfricke-samsung828e59d2021-08-22 23:20:49 -07001162 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1163 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001164 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001165 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001166
1167 const auto *ray_tracing_motion_blur_features =
1168 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1169 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001170 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001171 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001172
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001173 const auto *primitive_topology_list_restart_features =
1174 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1175 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001176 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001177 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001178
ziga-lunarge1988962021-09-16 13:32:34 +02001179 const auto *zero_initialize_work_group_memory_features =
1180 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1181 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001182 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001183 }
1184
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001185 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1186 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001187 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001188 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001189
Tony-LunarG69604c42021-11-22 16:00:12 -07001190 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1191 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001192 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001193 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001194
1195 const auto *primitives_generated_query_features =
1196 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1197 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001198 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001199 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001200
1201 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1202 if (image_2d_view_of_3d_features) {
1203 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1204 }
Nathaniel Cesario553ab032022-04-14 10:56:22 -06001205
1206 const auto graphics_pipeline_library_features =
1207 LvlFindInChain<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(pCreateInfo->pNext);
1208 if (graphics_pipeline_library_features) {
1209 enabled_features.graphics_pipeline_library_features = *graphics_pipeline_library_features;
1210 }
ziga-lunarge25f5f02022-04-16 15:07:35 +02001211
1212 const auto shader_subgroup_uniform_control_flow_features =
1213 LvlFindInChain<VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR>(pCreateInfo->pNext);
1214 if (shader_subgroup_uniform_control_flow_features) {
1215 enabled_features.shader_subgroup_uniform_control_flow_features = *shader_subgroup_uniform_control_flow_features;
1216 }
Mike Schuchardt840f1252022-05-11 11:31:25 -07001217
sjfrickee9b39372022-05-22 13:02:17 +09001218 const auto ray_tracing_maintenance1_features =
Mike Schuchardt840f1252022-05-11 11:31:25 -07001219 LvlFindInChain<VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR>(pCreateInfo->pNext);
1220 if (ray_tracing_maintenance1_features) {
1221 enabled_features.ray_tracing_maintenance1_features= *ray_tracing_maintenance1_features;
1222 }
Tony-LunarG206b1bb2022-06-13 12:20:05 -06001223
1224 const auto non_seamless_cube_map_features =
1225 LvlFindInChain<VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT>(pCreateInfo->pNext);
1226 if (non_seamless_cube_map_features) {
1227 enabled_features.non_seamless_cube_map_features = *non_seamless_cube_map_features;
1228 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001229 }
1230
locke-lunargd556cc32019-09-17 01:21:23 -06001231 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001232 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1233 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001234
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001235 {
1236 uint32_t n_props = 0;
1237 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001238 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001239 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001240 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001241
1242 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001243 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001244 }
1245
1246 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1247 // a path to grab that information from the physical device. This
1248 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1249 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001250 has_format_feature2 =
1251 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1252 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001253 }
1254
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001255 const auto &dev_ext = device_extensions;
1256 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001257
Tony-LunarG273f32f2021-09-28 08:56:30 -06001258 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1259 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001260 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1261 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001262 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001263 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001264 } else {
1265 // VkPhysicalDeviceVulkan11Properties
1266 //
1267 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1268
1269 if (dev_ext.vk_khr_multiview) {
1270 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001271 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1272 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1273 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001274 }
1275
1276 if (dev_ext.vk_khr_maintenance3) {
1277 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001278 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1279 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1280 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001281 }
1282
1283 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001284 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001285 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1286 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1287 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001288 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001289
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001290 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1291 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1292 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1293 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001294
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001295 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001296 }
1297
1298 // VkPhysicalDeviceVulkan12Properties
1299 //
1300 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1301
1302 if (dev_ext.vk_ext_descriptor_indexing) {
1303 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001304 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1305 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001307 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001308 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001309 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001310 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001311 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001312 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001313 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001314 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001315 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001316 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001317 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1318 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1319 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001320 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001321 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001322 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001323 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001324 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001325 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001326 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001327 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001328 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001329 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001330 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001331 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001332 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001333 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001334 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001335 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001336 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001337 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001338 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001339 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001340 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001341 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001342 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001343 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001344 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001345 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001346 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001347 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001348 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1349 }
1350
1351 if (dev_ext.vk_khr_depth_stencil_resolve) {
1352 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001353 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1354 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1355 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1356 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1357 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001358 }
1359
1360 if (dev_ext.vk_khr_timeline_semaphore) {
1361 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001362 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1363 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001364 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1365 }
1366
1367 if (dev_ext.vk_ext_sampler_filter_minmax) {
1368 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001369 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1370 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001371 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001372 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001373 }
1374
1375 if (dev_ext.vk_khr_shader_float_controls) {
1376 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001377 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1378 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1379 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1380 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001381 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001382 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001383 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001384 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001385 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001386 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1387 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1388 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1389 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1390 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1391 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1392 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1393 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1394 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1395 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1396 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1397 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001398 }
locke-lunargd556cc32019-09-17 01:21:23 -06001399 }
1400
sfricke-samsung828e59d2021-08-22 23:20:49 -07001401 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001402 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1403 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1404 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1405 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1406 &phys_dev_props->inline_uniform_block_props);
1407 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1408 &phys_dev_props->vtx_attrib_divisor_props);
1409 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1410 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1411 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1412 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1413 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1414 &phys_dev_props->texel_buffer_alignment_props);
1415 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1416 &phys_dev_props->fragment_density_map_props);
1417 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1418 &phys_dev_props->fragment_density_map2_props);
1419 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001420 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001421 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1422 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1423 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1424 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1425 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1426 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1427 &phys_dev_props->fragment_shading_rate_props);
1428 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1429 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1430 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1431 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1432 &phys_dev_props->blend_operation_advanced_props);
1433 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1434 &phys_dev_props->conservative_rasterization_props);
1435 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1436 &phys_dev_props->subgroup_size_control_props);
ziga-lunarge25f5f02022-04-16 15:07:35 +02001437 if (api_version >= VK_API_VERSION_1_1) {
1438 GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_properties);
1439 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001440
sfricke-samsung45996a42021-09-16 13:45:27 -07001441 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001442 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001443 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1444 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001445 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1446 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001447
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001448 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001449 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1450 NULL);
1451 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001452
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001453 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1454 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001455 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001456
locke-lunargd556cc32019-09-17 01:21:23 -06001457 // Store queue family data
1458 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1459 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001460 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001461 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1462 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001463 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001464 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001465 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001466 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1467 VkQueue queue = VK_NULL_HANDLE;
1468 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1469 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1470 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1471 get_info.flags = queue_info.flags;
1472 get_info.queueFamilyIndex = queue_info.queue_family_index;
1473 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001474 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001475 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001476 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001477 }
1478 assert(queue != VK_NULL_HANDLE);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001479 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001480 }
locke-lunargd556cc32019-09-17 01:21:23 -06001481 }
1482 }
1483}
1484
1485void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1486 if (!device) return;
1487
Jeremy Gebbend177d922021-10-28 13:42:10 -06001488 command_pool_map_.clear();
1489 assert(command_buffer_map_.empty());
1490 pipeline_map_.clear();
1491 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001492
1493 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001494 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001495 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001496 assert(descriptor_set_map_.empty());
1497 desc_template_map_.clear();
1498 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001499 // Because swapchains are associated with Surfaces, which are at instance level,
1500 // they need to be explicitly destroyed here to avoid continued references to
1501 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001502 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001503 entry.second->Destroy();
1504 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001505 swapchain_map_.clear();
1506 image_view_map_.clear();
1507 image_map_.clear();
1508 buffer_view_map_.clear();
1509 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001510 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001511 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001512}
1513
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001514void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1515 VkFence fence, VkResult result) {
1516 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001517 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001518
Jeremy Gebben57642982021-09-14 14:14:55 -06001519 uint64_t early_retire_seq = 0;
1520
1521 if (submitCount == 0) {
1522 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001523 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001524 early_retire_seq = queue_state->Submit(std::move(submission));
1525 }
locke-lunargd556cc32019-09-17 01:21:23 -06001526
1527 // Now process each individual submit
1528 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001529 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001530 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001531 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001532 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001533 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001534 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1535 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1536 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1537 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001538 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001539 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001540
locke-lunargd556cc32019-09-17 01:21:23 -06001541 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001542 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001543 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1544 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1545 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1546 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001547 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001548 }
1549
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001550 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001551 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001552
locke-lunargd556cc32019-09-17 01:21:23 -06001553 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001554 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1555 if (cb_state) {
1556 submission.AddCommandBuffer(std::move(cb_state));
1557 }
locke-lunargd556cc32019-09-17 01:21:23 -06001558 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001559 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001560 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001561 }
1562 auto submit_seq = queue_state->Submit(std::move(submission));
1563 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001564 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001565
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001566 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001567 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001568 }
1569}
1570
Tony-LunarG26fe2842021-11-16 14:07:59 -07001571void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1572 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001573 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001574 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001575 uint64_t early_retire_seq = 0;
1576 if (submitCount == 0) {
1577 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001578 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001579 early_retire_seq = queue_state->Submit(std::move(submission));
1580 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001581
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001582 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1583 CB_SUBMISSION submission;
1584 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001585 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1586 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001587 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001588 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001589 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1590 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001591 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001592 }
1593 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1594 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1595
1596 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001597 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001598 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001599 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001600 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001601 }
1602 auto submit_seq = queue_state->Submit(std::move(submission));
1603 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001604 }
locke-lunargd556cc32019-09-17 01:21:23 -06001605 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001606 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001607 }
1608}
1609
Tony-LunarG26fe2842021-11-16 14:07:59 -07001610void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1611 VkFence fence, VkResult result) {
1612 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1613}
1614
1615void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1616 VkFence fence, VkResult result) {
1617 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1618}
1619
locke-lunargd556cc32019-09-17 01:21:23 -06001620void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1621 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1622 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001623 if (VK_SUCCESS != result) {
1624 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001625 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001626 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1627 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1628 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1629
1630 layer_data::optional<DedicatedBinding> dedicated_binding;
1631
1632 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1633 if (dedicated) {
1634 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001635 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001636 assert(buffer_state);
1637 if (!buffer_state) {
1638 return;
1639 }
1640 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1641 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001642 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001643 assert(image_state);
1644 if (!image_state) {
1645 return;
1646 }
1647 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1648 }
1649 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001650 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1651 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001652 return;
1653}
1654
1655void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001656 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001657 if (mem_info) {
1658 fake_memory.Free(mem_info->fake_base_address);
1659 }
1660 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001661}
1662
1663void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1664 VkFence fence, VkResult result) {
1665 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001666 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001667
Jeremy Gebben57642982021-09-14 14:14:55 -06001668 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001669
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001670 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1671 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001672 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001673 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1674 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1675 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001676 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001677 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001678 if (buffer_state) {
1679 buffer_state->BindMemory(buffer_state.get(), mem_state, sparse_binding.memoryOffset,
1680 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001681 }
locke-lunargd556cc32019-09-17 01:21:23 -06001682 }
1683 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001684 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1685 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1686 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001687 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001688 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001689 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001690 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1691 // See: VUID-vkGetImageSubresourceLayout-image-01895
1692 if (!image_state->fragment_encoder) {
1693 image_state->fragment_encoder =
1694 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1695 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001696 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset,
1697 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001698 }
locke-lunargd556cc32019-09-17 01:21:23 -06001699 }
1700 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001701 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1702 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1703 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001704 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1705 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Aitor Camacho3294edd2022-05-16 22:34:19 +02001706 VkDeviceSize offset = sparse_binding.offset.z * sparse_binding.offset.y * sparse_binding.offset.x * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001707 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001708 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001709 if (image_state) {
aitor-lunargf9638d52022-04-20 21:33:44 +02001710 // An Android special image cannot get VkSubresourceLayout until the image binds a memory.
1711 // See: VUID-vkGetImageSubresourceLayout-image-01895
1712 if (!image_state->fragment_encoder) {
1713 image_state->fragment_encoder =
1714 layer_data::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
1715 }
Aitor Camacho3294edd2022-05-16 22:34:19 +02001716 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset, offset, size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001717 }
locke-lunargd556cc32019-09-17 01:21:23 -06001718 }
1719 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001720 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001721 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001722 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001723 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001724 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001725 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001726 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001727 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001728 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001729 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001730 auto submit_seq = queue_state->Submit(std::move(submission));
1731 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001732 }
1733
1734 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001735 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001736 }
1737}
1738
1739void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1740 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1741 VkResult result) {
1742 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06001743 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext), pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001744}
1745
Mike Schuchardt2df08912020-12-15 16:28:09 -08001746void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1747 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001748 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1749 if (semaphore_state) {
1750 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001751 }
1752}
1753
Mike Schuchardt2df08912020-12-15 16:28:09 -08001754void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001755 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001756 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001757 if (semaphore_state) {
1758 semaphore_state->RetireTimeline(pSignalInfo->value);
1759 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001760}
1761
locke-lunargd556cc32019-09-17 01:21:23 -06001762void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001763 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001764 if (mem_info) {
1765 mem_info->mapped_range.offset = offset;
1766 mem_info->mapped_range.size = size;
1767 mem_info->p_driver_data = *ppData;
1768 }
1769}
1770
locke-lunargd556cc32019-09-17 01:21:23 -06001771void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1772 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1773 if (VK_SUCCESS != result) return;
1774
1775 // When we know that all fences are complete we can clean/remove their CBs
1776 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1777 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001778 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001779 if (fence_state) {
1780 fence_state->Retire();
1781 }
locke-lunargd556cc32019-09-17 01:21:23 -06001782 }
1783 }
1784 // NOTE : Alternate case not handled here is when some fences have completed. In
1785 // this case for app to guarantee which fences completed it will have to call
1786 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1787}
1788
John Zulauff89de662020-04-13 18:57:34 -06001789void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1790 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001791 if (VK_SUCCESS != result) return;
1792
Jeremy Gebben15332642021-12-15 19:33:15 -07001793 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1794 // the application calls vkGetSemaphoreCounterValue() on each of them.
1795 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1796 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1797 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1798 if (semaphore_state) {
1799 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1800 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001801 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001802 }
1803}
1804
John Zulauff89de662020-04-13 18:57:34 -06001805void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1806 VkResult result) {
1807 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1808}
1809
1810void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1811 uint64_t timeout, VkResult result) {
1812 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1813}
1814
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001815void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1816 VkResult result) {
1817 if (VK_SUCCESS != result) return;
1818
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001819 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001820 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001821 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001822 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001823}
1824
1825void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1826 VkResult result) {
1827 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1828}
1829void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1830 VkResult result) {
1831 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1832}
1833
locke-lunargd556cc32019-09-17 01:21:23 -06001834void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1835 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001836 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001837 if (fence_state) {
1838 fence_state->Retire();
1839 }
locke-lunargd556cc32019-09-17 01:21:23 -06001840}
1841
Yilong Lice03a312022-01-02 02:08:35 -08001842void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1843 if (Get<QUEUE_STATE>(queue) == nullptr) {
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001844 Add(CreateQueue(queue, queue_family_index, flags));
Yilong Lice03a312022-01-02 02:08:35 -08001845 }
1846}
1847
1848void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1849 VkQueue *pQueue) {
1850 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1851}
1852
1853void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1854 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1855}
1856
locke-lunargd556cc32019-09-17 01:21:23 -06001857void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1858 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001859 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001860 if (queue_state) {
1861 queue_state->Retire();
1862 }
locke-lunargd556cc32019-09-17 01:21:23 -06001863}
1864
1865void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1866 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001867 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001868 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001869 }
1870}
1871
1872void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001873 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001874}
1875
1876void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1877 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001878 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001879}
1880
1881void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001882 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001883}
1884
1885void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1886 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001887 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001888}
1889
locke-lunargd556cc32019-09-17 01:21:23 -06001890void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001891 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001892 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001893 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001894 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001895 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02001896 buffer_state->BindMemory(buffer_state.get(), mem_state, memoryOffset, 0u, buffer_state->requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001897 }
locke-lunargd556cc32019-09-17 01:21:23 -06001898 }
1899}
1900
1901void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1902 VkDeviceSize memoryOffset, VkResult result) {
1903 if (VK_SUCCESS != result) return;
1904 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1905}
1906
1907void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001908 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001909 for (uint32_t i = 0; i < bindInfoCount; i++) {
1910 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1911 }
1912}
1913
1914void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001915 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001916 for (uint32_t i = 0; i < bindInfoCount; i++) {
1917 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1918 }
1919}
1920
Spencer Fricke6c127102020-04-16 06:25:20 -07001921void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001922 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001923 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001924 buffer_state->memory_requirements_checked = true;
1925 }
1926}
1927
1928void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1929 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001930 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001931}
1932
1933void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001934 const VkBufferMemoryRequirementsInfo2 *pInfo,
1935 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001936 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001937}
1938
1939void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001940 const VkBufferMemoryRequirementsInfo2 *pInfo,
1941 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001942 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001943}
1944
Spencer Fricke6c127102020-04-16 06:25:20 -07001945void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001946 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001947 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001948 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001949 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001950 if (plane_info != nullptr) {
1951 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001952 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001953 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001954 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001955 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001956 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001957 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001958 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001959 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001960 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001961 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001962 }
locke-lunargd556cc32019-09-17 01:21:23 -06001963 }
1964}
1965
1966void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1967 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001968 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001969}
1970
1971void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1972 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001973 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001974}
1975
1976void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1977 const VkImageMemoryRequirementsInfo2 *pInfo,
1978 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001979 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001980}
1981
locke-lunargd556cc32019-09-17 01:21:23 -06001982void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1983 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1984 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001985 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001986 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001987}
1988
1989void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001990 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1991 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001992 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001993 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001994}
1995
1996void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001997 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1998 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001999 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06002000 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002001}
2002
2003void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2004 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002005 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06002006}
2007
2008void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2009 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002010 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002011}
2012
2013void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2014 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002015 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002016}
2017
2018void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2019 const VkAllocationCallbacks *pAllocator) {
2020 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002021 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002022 // Any bound cmd buffers are now invalid
2023 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002024 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2025 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2026 custom_border_color_sampler_count--;
2027 }
locke-lunargd556cc32019-09-17 01:21:23 -06002028 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06002029 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002030}
2031
2032void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2033 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002034 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002035}
2036
2037void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2038 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002039 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002040}
2041
locke-lunargd556cc32019-09-17 01:21:23 -06002042void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2043 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002044 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2045 if (pool) {
2046 pool->Free(commandBufferCount, pCommandBuffers);
2047 }
locke-lunargd556cc32019-09-17 01:21:23 -06002048}
2049
2050void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2051 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2052 VkResult result) {
2053 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002054 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002055 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06002056}
2057
2058void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2059 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2060 VkResult result) {
2061 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002062
2063 uint32_t index_count = 0, n_perf_pass = 0;
2064 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002065 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002066 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002067 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002068
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002069 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002070 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2071 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2072 switch (counter.scope) {
2073 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002074 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002075 break;
2076 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002077 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002078 break;
2079 default:
2080 break;
2081 }
2082 }
2083
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002084 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002085 }
2086
Jeremy Gebben082a9832021-10-28 13:40:11 -06002087 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 -06002088
locke-lunargd556cc32019-09-17 01:21:23 -06002089}
2090
2091void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2092 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002093 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002094}
2095
2096void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2097 VkCommandPoolResetFlags flags, VkResult result) {
2098 if (VK_SUCCESS != result) return;
2099 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002100 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2101 if (pool) {
2102 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002103 }
2104}
2105
2106void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2107 VkResult result) {
2108 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002109 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002110 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002111 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002112 }
2113 }
2114}
2115
locke-lunargd556cc32019-09-17 01:21:23 -06002116void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2117 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002118 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002119}
2120
2121void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2122 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002123 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002124}
2125
2126void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2127 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2128 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002129 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002130}
2131
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002132std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2133 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2134 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2135 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2136}
2137
locke-lunargd556cc32019-09-17 01:21:23 -06002138bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2139 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2140 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002141 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002142 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002143 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2144 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2145 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2146 cgpl_state->pipe_state.reserve(count);
2147 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002148 const auto &create_info = pCreateInfos[i];
2149 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2150 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2151
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002152 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002153 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002154 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002155 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2156 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002157 } else {
2158 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2159 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2160 if (!is_graphics_lib && !has_link_info) {
2161 skip = true;
2162 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002163 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002164 cgpl_state->pipe_state.push_back(
2165 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002166 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002167 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002168}
2169
2170void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2171 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2172 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2173 VkResult result, void *cgpl_state_data) {
2174 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2175 // This API may create pipelines regardless of the return value
2176 for (uint32_t i = 0; i < count; i++) {
2177 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002178 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002179 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002180 }
2181 }
2182 cgpl_state->pipe_state.clear();
2183}
2184
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002185std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2186 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2187 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2188}
2189
locke-lunargd556cc32019-09-17 01:21:23 -06002190bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2191 const VkComputePipelineCreateInfo *pCreateInfos,
2192 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002193 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002194 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2195 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2196 ccpl_state->pipe_state.reserve(count);
2197 for (uint32_t i = 0; i < count; i++) {
2198 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002199 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002200 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002201 }
2202 return false;
2203}
2204
2205void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2206 const VkComputePipelineCreateInfo *pCreateInfos,
2207 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2208 VkResult result, void *ccpl_state_data) {
2209 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2210
2211 // This API may create pipelines regardless of the return value
2212 for (uint32_t i = 0; i < count; i++) {
2213 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002214 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002215 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002216 }
2217 }
2218 ccpl_state->pipe_state.clear();
2219}
2220
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002221std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2222 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2223 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2224}
2225
locke-lunargd556cc32019-09-17 01:21:23 -06002226bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2227 uint32_t count,
2228 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2229 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002230 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002231 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2232 crtpl_state->pipe_state.reserve(count);
2233 for (uint32_t i = 0; i < count; i++) {
2234 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002235 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002236 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002237 }
2238 return false;
2239}
2240
2241void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2242 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2243 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2244 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2245 // This API may create pipelines regardless of the return value
2246 for (uint32_t i = 0; i < count; i++) {
2247 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002248 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002249 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002250 }
2251 }
2252 crtpl_state->pipe_state.clear();
2253}
2254
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002255std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2256 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2257 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2258}
2259
sourav parmarcd5fb182020-07-17 12:58:44 -07002260bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2261 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002262 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2263 const VkAllocationCallbacks *pAllocator,
2264 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002265 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002266 crtpl_state->pipe_state.reserve(count);
2267 for (uint32_t i = 0; i < count; i++) {
2268 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002269 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002270 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002271 }
2272 return false;
2273}
2274
sourav parmarcd5fb182020-07-17 12:58:44 -07002275void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2276 VkPipelineCache pipelineCache, uint32_t count,
2277 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2278 const VkAllocationCallbacks *pAllocator,
2279 VkPipeline *pPipelines, VkResult result,
2280 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002281 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002282 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002283 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002284
2285 if (!operation_is_deferred) {
2286 for (uint32_t i = 0; i < count; i++) {
2287 if (pPipelines[i] != VK_NULL_HANDLE) {
2288 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2289 Add(std::move((crtpl_state->pipe_state)[i]));
2290 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002291 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002292 } else {
2293 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2294 if (wrap_handles) {
2295 deferredOperation = layer_data->Unwrap(deferredOperation);
2296 }
2297 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2298 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2299 if (find_res->first) {
2300 cleanup_fn = std::move(find_res->second);
2301 }
2302 auto &pipeline_states = crtpl_state->pipe_state;
2303 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2304 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2305 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2306 pipeline_states[i]->SetHandle(pipelines[i]);
2307 this->Add(std::move(pipeline_states[i]));
2308 }
2309 });
2310 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002311 }
2312 crtpl_state->pipe_state.clear();
2313}
2314
locke-lunargd556cc32019-09-17 01:21:23 -06002315void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2316 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2317 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002318 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002319 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2320 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002321 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002322 }
locke-lunargd556cc32019-09-17 01:21:23 -06002323}
2324
2325void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2326 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2327 const VkAllocationCallbacks *pAllocator,
2328 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2329 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002330 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002331}
2332
locke-lunargd556cc32019-09-17 01:21:23 -06002333void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2334 const VkAllocationCallbacks *pAllocator,
2335 VkPipelineLayout *pPipelineLayout, VkResult result) {
2336 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002337 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002338}
2339
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002340std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2341 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2342 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2343}
2344
locke-lunargd556cc32019-09-17 01:21:23 -06002345void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2346 const VkAllocationCallbacks *pAllocator,
2347 VkDescriptorPool *pDescriptorPool, VkResult result) {
2348 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002349 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002350}
2351
2352void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2353 VkDescriptorPoolResetFlags flags, VkResult result) {
2354 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002355 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2356 if (pool) {
2357 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002358 }
locke-lunargd556cc32019-09-17 01:21:23 -06002359}
2360
2361bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2362 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002363 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002364 // Always update common data
2365 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2366 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2367 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2368
2369 return false;
2370}
2371
2372// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2373void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2374 VkDescriptorSet *pDescriptorSets, VkResult result,
2375 void *ads_state_data) {
2376 if (VK_SUCCESS != result) return;
2377 // All the updates are contained in a single cvdescriptorset function
2378 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2379 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002380 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2381 if (pool_state) {
2382 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2383 }
locke-lunargd556cc32019-09-17 01:21:23 -06002384}
2385
2386void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2387 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002388 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2389 if (pool_state) {
2390 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002391 }
2392}
2393
2394void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2395 const VkWriteDescriptorSet *pDescriptorWrites,
2396 uint32_t descriptorCopyCount,
2397 const VkCopyDescriptorSet *pDescriptorCopies) {
2398 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2399 pDescriptorCopies);
2400}
2401
2402void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002403 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002404 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002405 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002406 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002407 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002408 }
2409}
2410
locke-lunargd556cc32019-09-17 01:21:23 -06002411void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2412 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002413 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002414 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002415
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002416 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002417}
2418
2419void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002420 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002421 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002422
2423 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002424}
2425
2426void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2427 VkResult result) {
2428 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002429 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2430 if (cb_state) {
2431 cb_state->Reset();
2432 }
locke-lunargd556cc32019-09-17 01:21:23 -06002433 }
2434}
2435
2436CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2437 // initially assume everything is static state
2438 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2439
2440 if (ds) {
2441 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002442 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002443 }
2444 }
locke-lunargd556cc32019-09-17 01:21:23 -06002445 return flags;
2446}
2447
2448// Validation cache:
2449// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002450
2451void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2452 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002453 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002454 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002455 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002456
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002457 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002458 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002459 const auto *raster_state = pipe_state->RasterizationState();
2460 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002461 const auto *viewport_state = pipe_state->ViewportState();
2462 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002463 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002464 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002465 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002466 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002467
2468 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002469 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2470 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002471 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002472 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002473 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002474 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002475 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002476 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002477
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002478 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002479 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2480 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2481 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002482 if (!has_dynamic_viewport_count) {
2483 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002484 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002485 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2486 // should become = ~uint32_t(0) if the other interpretation is correct.
2487 }
2488 }
2489 if (!has_dynamic_scissor_count) {
2490 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002491 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002492 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2493 // should become = ~uint32_t(0) if the other interpretation is correct.
2494 }
2495 }
locke-lunargd556cc32019-09-17 01:21:23 -06002496 }
Nathaniel Cesario62f03592022-07-11 09:19:20 -06002497 cb_state->BindPipeline(ConvertToLvlBindPoint(pipelineBindPoint), pipe_state.get());
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002498 if (!disabled[command_buffer_state]) {
2499 cb_state->AddChild(pipe_state);
2500 }
locke-lunargd556cc32019-09-17 01:21:23 -06002501}
2502
2503void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2504 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002505 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002506 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002507 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2508 cb_state->viewportMask |= bits;
2509 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002510
2511 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2512 for (size_t i = 0; i < viewportCount; ++i) {
2513 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2514 }
locke-lunargd556cc32019-09-17 01:21:23 -06002515}
2516
2517void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2518 uint32_t exclusiveScissorCount,
2519 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002520 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002521 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002522 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2523 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002524}
2525
2526void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2527 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002528 if (disabled[command_buffer_state]) return;
2529
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002530 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002531 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002532
2533 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002534 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002535 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002536 }
2537}
2538
2539void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2540 uint32_t viewportCount,
2541 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002542 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002543 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002544 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2545 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002546}
2547
2548void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2549 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2550 const VkAllocationCallbacks *pAllocator,
2551 VkAccelerationStructureNV *pAccelerationStructure,
2552 VkResult result) {
2553 if (VK_SUCCESS != result) return;
Aitor Camacho3294edd2022-05-16 22:34:19 +02002554 std::shared_ptr<ACCELERATION_STRUCTURE_STATE> state =
2555 std::make_shared<ACCELERATION_STRUCTURE_STATE_LINEAR>(device, *pAccelerationStructure, pCreateInfo);
2556 Add(std::move(state));
locke-lunargd556cc32019-09-17 01:21:23 -06002557}
2558
Jeff Bolz95176d02020-04-01 00:36:16 -05002559void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2560 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2561 const VkAllocationCallbacks *pAllocator,
2562 VkAccelerationStructureKHR *pAccelerationStructure,
2563 VkResult result) {
2564 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002565 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2566 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002567}
2568
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002569void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2570 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2571 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2572 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2573 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002574 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002575 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002576 dst_as_state->Build(&pInfos[i], true, *ppBuildRangeInfos);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002577 }
2578 }
2579}
2580
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002581// helper method for device side acceleration structure builds
2582void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2583 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2584 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2585 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsend7f13702021-10-28 16:05:51 +02002586 dst_as_state->Build(&info, false, nullptr);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002587 }
2588 if (disabled[command_buffer_state]) {
2589 return;
2590 }
2591 if (dst_as_state) {
2592 cb_state.AddChild(dst_as_state);
2593 }
2594 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2595 if (src_as_state) {
2596 cb_state.AddChild(src_as_state);
2597 }
2598 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2599 if (scratch_buffer) {
2600 cb_state.AddChild(scratch_buffer);
2601 }
2602
2603 for (uint32_t i = 0; i < info.geometryCount; i++) {
2604 // only one of pGeometries and ppGeometries can be non-null
2605 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2606 switch (geom.geometryType) {
2607 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2608 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2609 if (vertex_buffer) {
2610 cb_state.AddChild(vertex_buffer);
2611 }
2612 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2613 if (index_buffer) {
2614 cb_state.AddChild(index_buffer);
2615 }
2616 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2617 if (transform_buffer) {
2618 cb_state.AddChild(transform_buffer);
2619 }
2620 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2621 if (motion_data) {
2622 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2623 if (motion_buffer) {
2624 cb_state.AddChild(motion_buffer);
2625 }
2626 }
2627 } break;
2628 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2629 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2630 if (data_buffer) {
2631 cb_state.AddChild(data_buffer);
2632 }
2633 } break;
2634 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2635 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2636 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2637 // easily ensure that's true.
2638 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2639 if (data_buffer) {
2640 cb_state.AddChild(data_buffer);
2641 }
2642 } break;
2643 default:
2644 break;
2645 }
2646 }
2647}
2648
sourav parmarcd5fb182020-07-17 12:58:44 -07002649void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2650 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2651 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002652 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002653 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002654 return;
2655 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002656 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002657 for (uint32_t i = 0; i < infoCount; i++) {
2658 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002659 }
2660 cb_state->hasBuildAccelerationStructureCmd = true;
2661}
2662
2663void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2664 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2665 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2666 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002667 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2668 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002669 return;
2670 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002671 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002672 for (uint32_t i = 0; i < infoCount; i++) {
2673 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002674 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002675 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2676 if (indirect_buffer) {
2677 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002678 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002679 }
2680 }
2681 cb_state->hasBuildAccelerationStructureCmd = true;
2682}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002683
locke-lunargd556cc32019-09-17 01:21:23 -06002684void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002685 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002686 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002687 if (as_state != nullptr) {
2688 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002689 as_state->memory_requirements_checked = true;
2690 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002691 as_state->build_scratch_memory_requirements_checked = true;
2692 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002693 as_state->update_scratch_memory_requirements_checked = true;
2694 }
2695 }
2696}
2697
sourav parmarcd5fb182020-07-17 12:58:44 -07002698void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2699 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002700 if (VK_SUCCESS != result) return;
2701 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002702 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002703
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002704 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002705 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002706 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002707 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002708 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02002709 as_state->BindMemory(as_state.get(), mem_state, info.memoryOffset, 0u, as_state->memory_requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002710 }
locke-lunargd556cc32019-09-17 01:21:23 -06002711
2712 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002713 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002714 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002715 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2716 }
2717 }
2718 }
2719}
2720
2721void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2722 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2723 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002724 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2725 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002726 return;
2727 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002728 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002729
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002730 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002731 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002732 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002733 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002734 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002735 }
locke-lunargd556cc32019-09-17 01:21:23 -06002736 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002737 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002738 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002739 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002740 cb_state->AddChild(src_as_state);
2741 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002742 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2743 if (instance_buffer) {
2744 cb_state->AddChild(instance_buffer);
2745 }
2746 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2747 if (scratch_buffer) {
2748 cb_state->AddChild(scratch_buffer);
2749 }
2750
2751 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2752 const auto& geom = pInfo->pGeometries[i];
2753
2754 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2755 if (vertex_buffer) {
2756 cb_state->AddChild(vertex_buffer);
2757 }
2758 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2759 if (index_buffer) {
2760 cb_state->AddChild(index_buffer);
2761 }
2762 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2763 if (transform_buffer) {
2764 cb_state->AddChild(transform_buffer);
2765 }
2766
2767 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2768 if (aabb_buffer) {
2769 cb_state->AddChild(aabb_buffer);
2770 }
2771 }
2772
locke-lunargd556cc32019-09-17 01:21:23 -06002773 }
2774 cb_state->hasBuildAccelerationStructureCmd = true;
2775}
2776
2777void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2778 VkAccelerationStructureNV dst,
2779 VkAccelerationStructureNV src,
2780 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002781 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002782 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002783 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2784 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002785 if (!disabled[command_buffer_state]) {
2786 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2787 }
locke-lunargd556cc32019-09-17 01:21:23 -06002788 if (dst_as_state != nullptr && src_as_state != nullptr) {
2789 dst_as_state->built = true;
2790 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002791 }
2792 }
2793}
2794
Jeff Bolz95176d02020-04-01 00:36:16 -05002795void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2796 VkAccelerationStructureKHR accelerationStructure,
2797 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002798 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002799}
2800
Jeff Bolz95176d02020-04-01 00:36:16 -05002801void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2802 VkAccelerationStructureNV accelerationStructure,
2803 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002804 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002805}
2806
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002807void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2808 uint32_t viewportCount,
2809 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002810 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002811 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002812}
2813
locke-lunargd556cc32019-09-17 01:21:23 -06002814void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002815 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002816 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002817}
2818
2819void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2820 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002821 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002822 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002823}
2824
2825void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2826 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002827 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002828 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002829}
2830
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002831void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2832 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002833 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002834 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002835 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2836 cb_state->scissorMask |= bits;
2837 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002838}
2839
locke-lunargd556cc32019-09-17 01:21:23 -06002840void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002841 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002842 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002843}
2844
2845void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2846 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002847 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002848 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002849}
2850
2851void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2852 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002853 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002854 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002855}
2856
2857void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2858 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002859 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002860 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002861}
2862
2863void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2864 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002865 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002866 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002867}
2868
locke-lunargd556cc32019-09-17 01:21:23 -06002869// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2870void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2871 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2872 uint32_t firstSet, uint32_t setCount,
2873 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2874 const uint32_t *pDynamicOffsets) {
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->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002877 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002878 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002879
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002880 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2881 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002882}
2883
locke-lunargd556cc32019-09-17 01:21:23 -06002884void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2885 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2886 uint32_t set, uint32_t descriptorWriteCount,
2887 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002888 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002889 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002890 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002891}
2892
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002893void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2894 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2895 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002896 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2897 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002898 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002899 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2900 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002901
2902 auto &push_constant_data = cb_state->push_constant_data;
2903 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2904 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002905 cb_state->push_constant_pipeline_layout_set = layout;
2906
2907 auto flags = stageFlags;
2908 uint32_t bit_shift = 0;
2909 while (flags) {
2910 if (flags & 1) {
2911 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2912 const auto it = cb_state->push_constant_data_update.find(flag);
2913
2914 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002915 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002916 }
2917 }
2918 flags = flags >> 1;
2919 ++bit_shift;
2920 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002921 }
2922}
2923
locke-lunargd556cc32019-09-17 01:21:23 -06002924void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2925 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002926 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002927
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002928 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002929 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002930 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002931 cb_state->index_buffer_binding.offset = offset;
2932 cb_state->index_buffer_binding.index_type = indexType;
2933 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002934 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002935 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002936 }
locke-lunargd556cc32019-09-17 01:21:23 -06002937}
2938
2939void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2940 uint32_t bindingCount, const VkBuffer *pBuffers,
2941 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002942 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002943 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002944
2945 uint32_t end = firstBinding + bindingCount;
2946 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2947 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2948 }
2949
2950 for (uint32_t i = 0; i < bindingCount; ++i) {
2951 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002952 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002953 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002954 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2955 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002956 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002957 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002958 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002959 }
locke-lunargd556cc32019-09-17 01:21:23 -06002960 }
2961}
2962
2963void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2964 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002965 if (disabled[command_buffer_state]) return;
2966
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002967 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002968 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002969}
2970
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002971void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2972 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002973 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002974 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002975}
2976
2977void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2978 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002979 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002980 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2981
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002982 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2983 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002984}
2985
Tony-LunarGc43525f2021-11-15 16:12:38 -07002986void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2987 const VkDependencyInfo* pDependencyInfo) {
2988 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2989 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2990
2991 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2992 cb_state->RecordBarriers(*pDependencyInfo);
2993}
2994
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002995void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2996 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002997 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002998 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002999}
3000
3001void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3002 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003003 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003004 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003005}
3006
Tony-LunarGa2662db2021-11-16 07:26:24 -07003007void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
3008 VkPipelineStageFlags2 stageMask) {
3009 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3010 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
3011}
3012
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003013void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3014 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
3015 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3016 uint32_t bufferMemoryBarrierCount,
3017 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3018 uint32_t imageMemoryBarrierCount,
3019 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003020 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3021 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003022 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3023 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003024}
3025
3026void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3027 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003028 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06003029 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003030 const auto &dep_info = pDependencyInfos[i];
3031 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3032 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
3033 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06003034 }
3035}
3036
Tony-LunarG1364cf52021-11-17 16:10:11 -07003037void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3038 const VkDependencyInfo *pDependencyInfos) {
3039 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3040 for (uint32_t i = 0; i < eventCount; i++) {
3041 const auto &dep_info = pDependencyInfos[i];
3042 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3043 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
3044 cb_state->RecordBarriers(dep_info);
3045 }
3046}
3047
Jeremy Gebben79649152021-06-22 14:46:24 -06003048void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3049 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3050 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3051 uint32_t bufferMemoryBarrierCount,
3052 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3053 uint32_t imageMemoryBarrierCount,
3054 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003055 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003056 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3057 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3058 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003059}
3060
3061void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3062 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003063 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003064 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3065 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003066}
3067
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07003068void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
3069 const VkDependencyInfo *pDependencyInfo) {
3070 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3071 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
3072 cb_state->RecordBarriers(*pDependencyInfo);
3073}
3074
locke-lunargd556cc32019-09-17 01:21:23 -06003075void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3076 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003077 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003078
locke-lunargd556cc32019-09-17 01:21:23 -06003079 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003080 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003081 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003082 if (!disabled[query_validation]) {
3083 cb_state->BeginQuery(query);
3084 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003085 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003086 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003087 cb_state->AddChild(pool_state);
3088 }
locke-lunargd556cc32019-09-17 01:21:23 -06003089}
3090
3091void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003092 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003093 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003094 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003095 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003096 if (!disabled[query_validation]) {
3097 cb_state->EndQuery(query_obj);
3098 }
3099 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003100 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003101 cb_state->AddChild(pool_state);
3102 }
locke-lunargd556cc32019-09-17 01:21:23 -06003103}
3104
3105void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3106 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003107 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003108 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003109
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003110 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003111 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003112
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003113 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003114 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003115 cb_state->AddChild(pool_state);
3116 }
locke-lunargd556cc32019-09-17 01:21:23 -06003117}
3118
3119void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3120 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3121 VkDeviceSize dstOffset, VkDeviceSize stride,
3122 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003123 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3124
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003125 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003126 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003127 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003128 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003129 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003130 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003131}
3132
3133void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3134 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003135 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003136 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003137}
3138
3139void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3140 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3141 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003142 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003143 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003144}
3145
Tony-LunarGde9936b2021-11-17 15:34:11 -07003146void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3147 VkQueryPool queryPool, uint32_t slot) {
3148 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3149 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3150}
3151
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003152void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3153 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3154 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3155 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003156 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003157 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
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 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003162 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003163}
3164
locke-lunargd556cc32019-09-17 01:21:23 -06003165void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3166 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3167 VkResult result) {
3168 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003169
Jeremy Gebben88f58142021-06-01 10:07:52 -06003170 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003171 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003172 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003173
locke-lunargd556cc32019-09-17 01:21:23 -06003174 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003175 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003176 }
3177 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003178
Jeremy Gebben9f537102021-10-05 16:37:12 -06003179 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003180 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003181}
3182
locke-lunargd556cc32019-09-17 01:21:23 -06003183void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3184 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3185 VkResult result) {
3186 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003187 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003188}
3189
Mike Schuchardt2df08912020-12-15 16:28:09 -08003190void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003191 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3192 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003193 if (VK_SUCCESS != result) return;
3194
Jeremy Gebben082a9832021-10-28 13:40:11 -06003195 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003196}
3197
Mike Schuchardt2df08912020-12-15 16:28:09 -08003198void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003199 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3200 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003201 if (VK_SUCCESS != result) return;
3202
Jeremy Gebben082a9832021-10-28 13:40:11 -06003203 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003204}
3205
locke-lunargd556cc32019-09-17 01:21:23 -06003206void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3207 const VkRenderPassBeginInfo *pRenderPassBegin,
3208 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003209 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003210 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003211}
3212
3213void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3214 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003215 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003216 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003217 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003218}
3219
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003220void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3221 uint32_t counterBufferCount,
3222 const VkBuffer *pCounterBuffers,
3223 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003224 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003225
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003226 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003227 cb_state->transform_feedback_active = true;
3228}
3229
3230void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3231 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3232 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003233 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003234
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003235 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003236 cb_state->transform_feedback_active = false;
3237}
3238
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003239void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3240 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003241 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003242
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003243 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003244 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003245 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3246 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003247}
3248
3249void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003250 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003251
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003252 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003253 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003254 cb_state->conditional_rendering_inside_render_pass = false;
3255 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003256}
3257
amhagana448ea52021-11-02 14:09:14 -04003258void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003259 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003260 cb_state->activeRenderPass = nullptr;
3261}
3262
3263void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3264 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003265 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003266 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3267}
3268
Tony-LunarG40b33882021-12-02 12:40:11 -07003269void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3270 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3271 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3272}
3273
amhagana448ea52021-11-02 14:09:14 -04003274void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3275 RecordCmdEndRenderingRenderPassState(commandBuffer);
3276}
3277
Tony-LunarG40b33882021-12-02 12:40:11 -07003278void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3279 RecordCmdEndRenderingRenderPassState(commandBuffer);
3280}
3281
Tony-LunarG977448c2019-12-02 14:52:02 -07003282void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3283 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003284 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003285 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003286 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003287}
3288
locke-lunargd556cc32019-09-17 01:21:23 -06003289void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003290 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003291 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003292}
3293
3294void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003295 const VkSubpassBeginInfo *pSubpassBeginInfo,
3296 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003297 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003298 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003299}
3300
Tony-LunarG977448c2019-12-02 14:52:02 -07003301void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003302 const VkSubpassBeginInfo *pSubpassBeginInfo,
3303 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003304 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003305 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003306}
3307
3308void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003309 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003310 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003311}
3312
3313void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003314 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003315 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003316 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003317}
3318
Tony-LunarG977448c2019-12-02 14:52:02 -07003319void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003320 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003321 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003322 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003323}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003324
locke-lunargd556cc32019-09-17 01:21:23 -06003325void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3326 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003327 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003328
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003329 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003330}
3331
3332void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3333 VkFlags flags, void **ppData, VkResult result) {
3334 if (VK_SUCCESS != result) return;
3335 RecordMappedMemory(mem, offset, size, ppData);
3336}
3337
3338void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003339 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003340 if (mem_info) {
3341 mem_info->mapped_range = MemRange();
3342 mem_info->p_driver_data = nullptr;
3343 }
3344}
3345
3346void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003347 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003348 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003349 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3350 // See: VUID-vkGetImageSubresourceLayout-image-01895
3351 image_state->fragment_encoder =
3352 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003353 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003354 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003355 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003356 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003357 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003358
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003359 if (!swapchain_image.fake_base_address) {
3360 auto size = image_state->fragment_encoder->TotalSize();
3361 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003362 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003363 // All images bound to this swapchain and index are aliases
3364 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003365 }
3366 } else {
3367 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003368 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003369 if (mem_info) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02003370 VkDeviceSize plane_index = 0u;
3371 if (image_state->disjoint && image_state->IsExternalAHB() == false) {
3372 auto plane_info = LvlFindInChain<VkBindImagePlaneMemoryInfo>(bindInfo.pNext);
3373 const VkImageAspectFlagBits aspect = plane_info->planeAspect;
3374 switch (aspect) {
3375 case VK_IMAGE_ASPECT_PLANE_0_BIT:
3376 plane_index = 0;
3377 break;
3378 case VK_IMAGE_ASPECT_PLANE_1_BIT:
3379 plane_index = 1;
3380 break;
3381 case VK_IMAGE_ASPECT_PLANE_2_BIT:
3382 plane_index = 2;
3383 break;
3384 default:
3385 assert(false); // parameter validation should have caught this
3386 break;
3387 }
3388 }
3389 image_state->BindMemory(
3390 image_state.get(), mem_info, bindInfo.memoryOffset, plane_index,
3391 image_state->requirements[static_cast<decltype(image_state->requirements)::size_type>(plane_index)].size);
locke-lunargd556cc32019-09-17 01:21:23 -06003392 }
locke-lunargd556cc32019-09-17 01:21:23 -06003393 }
locke-lunargd556cc32019-09-17 01:21:23 -06003394 }
3395}
3396
3397void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3398 VkDeviceSize memoryOffset, VkResult result) {
3399 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003400 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003401 bind_info.image = image;
3402 bind_info.memory = mem;
3403 bind_info.memoryOffset = memoryOffset;
3404 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003405}
3406
3407void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003408 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003409 if (VK_SUCCESS != result) return;
3410 for (uint32_t i = 0; i < bindInfoCount; i++) {
3411 UpdateBindImageMemoryState(pBindInfos[i]);
3412 }
3413}
3414
3415void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003416 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003417 if (VK_SUCCESS != result) return;
3418 for (uint32_t i = 0; i < bindInfoCount; i++) {
3419 UpdateBindImageMemoryState(pBindInfos[i]);
3420 }
3421}
3422
3423void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003424 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003425 if (event_state) {
3426 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3427 }
locke-lunargd556cc32019-09-17 01:21:23 -06003428}
3429
3430void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3431 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3432 VkResult result) {
3433 if (VK_SUCCESS != result) return;
3434 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3435 pImportSemaphoreFdInfo->flags);
3436}
3437
3438void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003439 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003440 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003441 if (semaphore_state) {
3442 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003443 }
3444}
3445
3446#ifdef VK_USE_PLATFORM_WIN32_KHR
3447void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3448 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3449 if (VK_SUCCESS != result) return;
3450 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3451 pImportSemaphoreWin32HandleInfo->flags);
3452}
3453
3454void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3455 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3456 HANDLE *pHandle, VkResult result) {
3457 if (VK_SUCCESS != result) return;
3458 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3459}
3460
3461void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3462 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3463 if (VK_SUCCESS != result) return;
3464 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3465 pImportFenceWin32HandleInfo->flags);
3466}
3467
3468void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3469 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3470 HANDLE *pHandle, VkResult result) {
3471 if (VK_SUCCESS != result) return;
3472 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3473}
3474#endif
3475
3476void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3477 VkResult result) {
3478 if (VK_SUCCESS != result) return;
3479 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3480}
3481
Mike Schuchardt2df08912020-12-15 16:28:09 -08003482void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3483 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003484 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003485
3486 if (fence_node) {
3487 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003488 }
3489}
3490
3491void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3492 VkResult result) {
3493 if (VK_SUCCESS != result) return;
3494 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3495}
3496
Mike Schuchardt2df08912020-12-15 16:28:09 -08003497void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003498 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003499 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003500 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003501 }
3502}
3503
3504void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3505 VkResult result) {
3506 if (VK_SUCCESS != result) return;
3507 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3508}
3509
3510void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3511 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3512 if (VK_SUCCESS != result) return;
Tony-LunarG285dbdc2022-07-15 09:42:54 -06003513 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003514}
3515
3516void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003517 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003518 SWAPCHAIN_NODE *old_swapchain_state) {
3519 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003520 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003521 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003522 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003523 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3524 surface_state->AddParent(swapchain.get());
3525 surface_state->swapchain = swapchain.get();
3526 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003527 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003528 } else {
3529 surface_state->swapchain = nullptr;
3530 }
3531 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003532 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003533 if (old_swapchain_state) {
3534 old_swapchain_state->retired = true;
3535 }
3536 return;
3537}
3538
3539void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3540 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3541 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003542 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003543 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003544 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003545}
3546
3547void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3548 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003549 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003550}
3551
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003552void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3553 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3554 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3555 VkResult result) {
3556 if (VK_SUCCESS != result) return;
3557 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003558 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003559}
3560
locke-lunargd556cc32019-09-17 01:21:23 -06003561void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003562 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003563 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003564 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3565 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3566 if (semaphore_state) {
3567 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003568 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003569 }
3570
3571 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3572 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3573 // 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
3574 // confused itself just as much.
3575 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3576 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3577 // Mark the image as having been released to the WSI
3578 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3579 if (swapchain_data) {
3580 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3581 if (present_id_info) {
3582 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3583 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3584 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003585 }
3586 }
locke-lunargd556cc32019-09-17 01:21:23 -06003587 }
locke-lunargd556cc32019-09-17 01:21:23 -06003588}
3589
3590void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3591 const VkSwapchainCreateInfoKHR *pCreateInfos,
3592 const VkAllocationCallbacks *pAllocator,
3593 VkSwapchainKHR *pSwapchains, VkResult result) {
3594 if (pCreateInfos) {
3595 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003596 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003597 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003598 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3599 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003600 }
3601 }
3602}
3603
3604void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3605 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003606 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003607 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003608 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3609 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003610 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003611 }
3612
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003613 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003614 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003615 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3616 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003617 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003618 }
3619
3620 // Mark the image as acquired.
3621 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3622 if (swapchain_data) {
3623 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003624 }
3625}
3626
3627void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3628 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3629 VkResult result) {
3630 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3631 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3632}
3633
3634void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3635 uint32_t *pImageIndex, VkResult result) {
3636 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3637 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3638 pAcquireInfo->fence, pImageIndex);
3639}
3640
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003641std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3642 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3643}
3644
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003645void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3646 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3647 VkResult result) {
3648 if (result != VK_SUCCESS) {
3649 return;
3650 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003651 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003652 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003653 // this can fail if the allocator fails
3654 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3655 if (result != VK_SUCCESS) {
3656 return;
3657 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003658 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003659 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3660 if (result != VK_SUCCESS) {
3661 return;
3662 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003663
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003664 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003665 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003666 }
Tony-LunarGffb5b522022-06-15 15:49:27 -06003667
3668#ifdef VK_USE_PLATFORM_METAL_EXT
3669 auto export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(pCreateInfo->pNext);
3670 while (export_metal_object_info) {
3671 export_metal_flags.push_back(export_metal_object_info->exportObjectType);
3672 export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(export_metal_object_info->pNext);
3673 }
3674#endif // VK_USE_PLATFORM_METAL_EXT
locke-lunargd556cc32019-09-17 01:21:23 -06003675}
3676
Tony-LunarGffb5b522022-06-15 15:49:27 -06003677
locke-lunargd556cc32019-09-17 01:21:23 -06003678// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003679static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003680 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003681}
3682
3683void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3684 uint32_t *pQueueFamilyPropertyCount,
3685 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003686 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3687 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003688 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003689}
3690
3691void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003692 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003693 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3694 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003695 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003696}
3697
3698void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003699 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003700 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3701 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003702 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003703}
3704void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3705 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003706 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003707}
3708
Jeremy Gebben082a9832021-10-28 13:40:11 -06003709void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003710
3711void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3712 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3713 const VkAllocationCallbacks *pAllocator,
3714 VkSurfaceKHR *pSurface, VkResult result) {
3715 if (VK_SUCCESS != result) return;
3716 RecordVulkanSurface(pSurface);
3717}
3718
3719#ifdef VK_USE_PLATFORM_ANDROID_KHR
3720void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3721 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3722 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3723 VkResult result) {
3724 if (VK_SUCCESS != result) return;
3725 RecordVulkanSurface(pSurface);
3726}
3727#endif // VK_USE_PLATFORM_ANDROID_KHR
3728
3729#ifdef VK_USE_PLATFORM_IOS_MVK
3730void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3731 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3732 VkResult result) {
3733 if (VK_SUCCESS != result) return;
3734 RecordVulkanSurface(pSurface);
3735}
3736#endif // VK_USE_PLATFORM_IOS_MVK
3737
3738#ifdef VK_USE_PLATFORM_MACOS_MVK
3739void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3740 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3741 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3742 VkResult result) {
3743 if (VK_SUCCESS != result) return;
3744 RecordVulkanSurface(pSurface);
3745}
3746#endif // VK_USE_PLATFORM_MACOS_MVK
3747
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003748#ifdef VK_USE_PLATFORM_METAL_EXT
3749void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3750 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3751 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3752 VkResult result) {
3753 if (VK_SUCCESS != result) return;
3754 RecordVulkanSurface(pSurface);
3755}
3756#endif // VK_USE_PLATFORM_METAL_EXT
3757
locke-lunargd556cc32019-09-17 01:21:23 -06003758#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3759void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3760 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3761 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3762 VkResult result) {
3763 if (VK_SUCCESS != result) return;
3764 RecordVulkanSurface(pSurface);
3765}
3766#endif // VK_USE_PLATFORM_WAYLAND_KHR
3767
3768#ifdef VK_USE_PLATFORM_WIN32_KHR
3769void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3770 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3771 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3772 VkResult result) {
3773 if (VK_SUCCESS != result) return;
3774 RecordVulkanSurface(pSurface);
3775}
3776#endif // VK_USE_PLATFORM_WIN32_KHR
3777
3778#ifdef VK_USE_PLATFORM_XCB_KHR
3779void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3780 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3781 VkResult result) {
3782 if (VK_SUCCESS != result) return;
3783 RecordVulkanSurface(pSurface);
3784}
3785#endif // VK_USE_PLATFORM_XCB_KHR
3786
3787#ifdef VK_USE_PLATFORM_XLIB_KHR
3788void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3789 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3790 VkResult result) {
3791 if (VK_SUCCESS != result) return;
3792 RecordVulkanSurface(pSurface);
3793}
3794#endif // VK_USE_PLATFORM_XLIB_KHR
3795
Niklas Haas8b84af12020-04-19 22:20:11 +02003796void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3797 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3798 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3799 VkResult result) {
3800 if (VK_SUCCESS != result) return;
3801 RecordVulkanSurface(pSurface);
3802}
3803
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003804void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3805 VkSurfaceKHR surface,
3806 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3807 VkResult result) {
3808 if (VK_SUCCESS != result) return;
3809 auto surface_state = Get<SURFACE_STATE>(surface);
3810 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3811}
3812
3813void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3814 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3815 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3816 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003817
3818 if (pSurfaceInfo->surface) {
3819 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3820 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3821 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3822 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3823 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3824 assert(pd_state);
3825 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3826 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003827}
3828
3829void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3830 VkSurfaceKHR surface,
3831 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3832 VkResult result) {
3833 auto surface_state = Get<SURFACE_STATE>(surface);
3834 VkSurfaceCapabilitiesKHR caps{
3835 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3836 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3837 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3838 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3839 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3840 };
3841 surface_state->SetCapabilities(physicalDevice, caps);
3842}
3843
locke-lunargd556cc32019-09-17 01:21:23 -06003844void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3845 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3846 VkBool32 *pSupported, VkResult result) {
3847 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003848 auto surface_state = Get<SURFACE_STATE>(surface);
3849 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3850}
3851
3852void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3853 VkSurfaceKHR surface,
3854 uint32_t *pPresentModeCount,
3855 VkPresentModeKHR *pPresentModes,
3856 VkResult result) {
3857 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3858
3859 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003860 if (surface) {
3861 auto surface_state = Get<SURFACE_STATE>(surface);
3862 surface_state->SetPresentModes(physicalDevice,
3863 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3864 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3865 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3866 assert(pd_state);
3867 pd_state->surfaceless_query_state.present_modes =
3868 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3869 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003870 }
3871}
3872
3873void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3874 uint32_t *pSurfaceFormatCount,
3875 VkSurfaceFormatKHR *pSurfaceFormats,
3876 VkResult result) {
3877 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3878
3879 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003880 if (surface) {
3881 auto surface_state = Get<SURFACE_STATE>(surface);
3882 surface_state->SetFormats(physicalDevice,
3883 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3884 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3885 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3886 assert(pd_state);
3887 pd_state->surfaceless_query_state.formats =
3888 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3889 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003890 }
3891}
3892
3893void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3894 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3895 uint32_t *pSurfaceFormatCount,
3896 VkSurfaceFormat2KHR *pSurfaceFormats,
3897 VkResult result) {
3898 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3899
3900 if (pSurfaceFormats) {
3901 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003902 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3903 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3904 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003905 if (pSurfaceInfo->surface) {
3906 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3907 surface_state->SetFormats(physicalDevice, std::move(fmts));
3908 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3909 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3910 assert(pd_state);
3911 pd_state->surfaceless_query_state.formats = std::move(fmts);
3912 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003913 }
locke-lunargd556cc32019-09-17 01:21:23 -06003914}
3915
locke-lunargd556cc32019-09-17 01:21:23 -06003916void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3917 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003918 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003919 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003920 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3921}
3922
3923void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003924 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003925 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003926 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3927}
3928
3929void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3930 const VkDebugUtilsLabelEXT *pLabelInfo) {
3931 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3932
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003933 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003934 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3935 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003936 cb_state->debug_label = LoggingLabel(pLabelInfo);
3937}
3938
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003939void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3940 uint32_t queueFamilyIndex,
3941 uint32_t *pCounterCount,
3942 VkPerformanceCounterKHR *pCounters) {
3943 if (NULL == pCounters) return;
3944
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003945 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3946 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003947
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003948 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3949 queue_family_counters->counters.resize(*pCounterCount);
3950 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003951
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003952 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003953}
3954
3955void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3956 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3957 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3958 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3959 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3960}
3961
3962void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3963 VkResult result) {
3964 if (result == VK_SUCCESS) performance_lock_acquired = true;
3965}
3966
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003967void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3968 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003969 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003970 cmd_buffer.second->performance_lock_released = true;
3971 }
3972}
3973
locke-lunargd556cc32019-09-17 01:21:23 -06003974void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003975 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003976 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003977 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003978}
3979
3980void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003981 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003982 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003983 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003984}
3985
Mike Schuchardt2df08912020-12-15 16:28:09 -08003986void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3987 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003988 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003989}
3990
Mike Schuchardt2df08912020-12-15 16:28:09 -08003991void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3992 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3993 const VkAllocationCallbacks *pAllocator,
3994 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3995 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003996 if (VK_SUCCESS != result) return;
3997 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3998}
3999
4000void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08004001 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4002 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004003 if (VK_SUCCESS != result) return;
4004 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
4005}
4006
4007void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004008 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004009 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004010 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
4011 assert(template_state);
4012 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06004013 // TODO: Record template push descriptor updates
4014 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004015 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06004016 }
4017 }
4018}
4019
4020void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
4021 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4022 const void *pData) {
4023 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4024}
4025
4026void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004027 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004028 const void *pData) {
4029 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4030}
4031
Mike Schuchardt2df08912020-12-15 16:28:09 -08004032void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
4033 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4034 VkPipelineLayout layout, uint32_t set,
4035 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004036 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004037
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004038 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07004039 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004040 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004041 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06004042 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004043 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004044 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06004045 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004046 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06004047 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004048 static_cast<uint32_t>(decoded_template.desc_writes.size()),
4049 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06004050 }
4051}
4052
4053void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
4054 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004055 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06004056 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004057 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004058 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06004059 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004060 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004061 }
4062}
4063
4064void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
4065 uint32_t *pPropertyCount,
4066 VkDisplayPlanePropertiesKHR *pProperties,
4067 VkResult result) {
4068 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4069 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4070}
4071
4072void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
4073 uint32_t *pPropertyCount,
4074 VkDisplayPlaneProperties2KHR *pProperties,
4075 VkResult result) {
4076 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4077 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4078}
4079
4080void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4081 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
4082 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004083 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004084 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004085 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004086}
4087
4088void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4089 uint32_t query, uint32_t index) {
4090 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004091 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004092 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004093 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004094}
4095
4096void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4097 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02004098 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004099
4100 if (create_info->format != VK_FORMAT_UNDEFINED) {
4101 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07004102 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004103 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4104 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004105 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004106
Jeremy Gebben082a9832021-10-28 13:40:11 -06004107 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004108}
4109
4110void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4111 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4112 const VkAllocationCallbacks *pAllocator,
4113 VkSamplerYcbcrConversion *pYcbcrConversion,
4114 VkResult result) {
4115 if (VK_SUCCESS != result) return;
4116 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4117}
4118
4119void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4120 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4121 const VkAllocationCallbacks *pAllocator,
4122 VkSamplerYcbcrConversion *pYcbcrConversion,
4123 VkResult result) {
4124 if (VK_SUCCESS != result) return;
4125 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4126}
4127
4128void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4129 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004130 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004131}
4132
4133void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4134 VkSamplerYcbcrConversion ycbcrConversion,
4135 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004136 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004137}
4138
Tony-LunarG977448c2019-12-02 14:52:02 -07004139void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4140 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004141 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004142 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004143
4144 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004145 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004146 if (!query_pool_state) return;
4147
4148 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004149 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4150 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004151 auto query_index = firstQuery + i;
4152 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004153 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004154 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004155 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004156 }
4157 }
locke-lunargd556cc32019-09-17 01:21:23 -06004158 }
4159}
4160
Tony-LunarG977448c2019-12-02 14:52:02 -07004161void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4162 uint32_t queryCount) {
4163 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4164}
4165
4166void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4167 uint32_t queryCount) {
4168 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4169}
4170
locke-lunargd556cc32019-09-17 01:21:23 -06004171void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004172 const UPDATE_TEMPLATE_STATE *template_state,
4173 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004174 // Translate the templated update into a normal update for validation...
4175 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4176 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4177 decoded_update.desc_writes.data(), 0, NULL);
4178}
4179
4180// Update the common AllocateDescriptorSetsData
4181void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004182 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004183 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004184 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004185 if (layout) {
4186 ds_data->layout_nodes[i] = layout;
4187 // Count total descriptors required per type
4188 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4189 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004190 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4191 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004192 }
4193 }
4194 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4195 }
4196}
4197
locke-lunargd556cc32019-09-17 01:21:23 -06004198void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4199 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004200 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004201 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004202}
4203
Tony-LunarG745150c2021-07-02 15:07:31 -06004204void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4205 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4206 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004207 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004208 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004209}
4210
locke-lunargd556cc32019-09-17 01:21:23 -06004211void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4212 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4213 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004214 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004215 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004216}
4217
Tony-LunarG745150c2021-07-02 15:07:31 -06004218void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4219 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4220 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4221 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004222 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004223 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004224}
4225
locke-lunargd556cc32019-09-17 01:21:23 -06004226void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4227 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004228 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004229 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004230 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004231 if (!disabled[command_buffer_state]) {
4232 cb_state->AddChild(buffer_state);
4233 }
locke-lunargd556cc32019-09-17 01:21:23 -06004234}
4235
4236void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4237 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004238 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004239 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004240 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004241 if (!disabled[command_buffer_state]) {
4242 cb_state->AddChild(buffer_state);
4243 }
locke-lunargd556cc32019-09-17 01:21:23 -06004244}
4245
4246void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004247 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004248 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004249}
4250
4251void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4252 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004253 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004254 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004255 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004256 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004257 cb_state->AddChild(buffer_state);
4258 }
locke-lunargd556cc32019-09-17 01:21:23 -06004259}
4260
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004261void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4262 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004263 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004264 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4265}
4266
4267void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4268 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004269 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004270 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4271}
4272
Tony-LunarG977448c2019-12-02 14:52:02 -07004273void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4274 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004275 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004276 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004277 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004278 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004279 auto buffer_state = Get<BUFFER_STATE>(buffer);
4280 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004281 cb_state->AddChild(buffer_state);
4282 cb_state->AddChild(count_buffer_state);
4283 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004284}
4285
locke-lunargd556cc32019-09-17 01:21:23 -06004286void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4287 VkDeviceSize offset, VkBuffer countBuffer,
4288 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4289 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004290 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004291 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004292}
4293
4294void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4295 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4296 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004297 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004298 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004299}
4300
4301void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4302 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004303 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004304 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004305 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004306 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004307 auto buffer_state = Get<BUFFER_STATE>(buffer);
4308 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004309 cb_state->AddChild(buffer_state);
4310 cb_state->AddChild(count_buffer_state);
4311 }
locke-lunargd556cc32019-09-17 01:21:23 -06004312}
4313
4314void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4315 VkDeviceSize offset, VkBuffer countBuffer,
4316 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4317 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004318 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004319 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004320}
4321
4322void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4323 VkDeviceSize offset, VkBuffer countBuffer,
4324 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4325 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004326 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004327 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004328}
4329
4330void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4331 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004332 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004333 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004334}
4335
4336void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4337 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004338 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004339 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004340 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004341 if (!disabled[command_buffer_state] && buffer_state) {
4342 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004343 }
4344}
4345
4346void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4347 VkDeviceSize offset, VkBuffer countBuffer,
4348 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4349 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004350 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004351 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004352 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004353 auto buffer_state = Get<BUFFER_STATE>(buffer);
4354 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004355 if (buffer_state) {
4356 cb_state->AddChild(buffer_state);
4357 }
4358 if (count_buffer_state) {
4359 cb_state->AddChild(count_buffer_state);
4360 }
locke-lunargd556cc32019-09-17 01:21:23 -06004361 }
4362}
4363
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004364void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4365 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4366 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4367 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4368 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4369 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4370 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004371 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004372 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004373 cb_state->hasTraceRaysCmd = true;
4374}
4375
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004376void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4377 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4378 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4379 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4380 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4381 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004382 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004383 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004384 cb_state->hasTraceRaysCmd = true;
4385}
4386
4387void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4388 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4389 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4390 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4391 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4392 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004393 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004394 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004395 cb_state->hasTraceRaysCmd = true;
4396}
4397
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004398std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4399 uint32_t unique_shader_id) const {
4400 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4401 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4402 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4403 : std::make_shared<SHADER_MODULE_STATE>();
4404}
4405
4406std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4407 uint32_t unique_shader_id,
4408 VkShaderModule handle) const {
4409 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4410 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4411 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4412 : std::make_shared<SHADER_MODULE_STATE>();
4413}
4414
sfricke-samsungf91881c2022-03-31 01:12:00 -05004415void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer,
4416 VkDeviceAddress indirectDeviceAddress) {
4417 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4418 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECT2KHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
4419 cb_state->hasTraceRaysCmd = true;
4420}
4421
locke-lunargd556cc32019-09-17 01:21:23 -06004422void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4423 const VkAllocationCallbacks *pAllocator,
4424 VkShaderModule *pShaderModule, VkResult result,
4425 void *csm_state_data) {
4426 if (VK_SUCCESS != result) return;
4427 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4428
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004429 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004430}
4431
John Zulauf22b0fbe2019-10-15 06:26:16 -06004432void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4433 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4434 VkResult result) {
4435 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004436 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004437
4438 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4439
4440 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004441 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004442 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004443 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004444
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004445 auto format_features = GetImageFormatFeatures(
4446 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4447 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004448
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004449 auto image_state =
4450 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004451 if (!swapchain_image.fake_base_address) {
4452 auto size = image_state->fragment_encoder->TotalSize();
4453 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004454 }
4455
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004456 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004457 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004458 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004459 }
4460 }
4461
4462 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004463 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4464 }
4465}
sourav parmar35e7a002020-06-09 17:58:44 -07004466
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004467void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4468 const VkCopyAccelerationStructureInfoKHR *pInfo,
4469 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004470 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4471 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004472 if (dst_as_state != nullptr && src_as_state != nullptr) {
4473 dst_as_state->built = true;
4474 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4475 }
4476}
4477
sourav parmar35e7a002020-06-09 17:58:44 -07004478void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4479 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004480 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004481 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004482 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004483 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4484 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004485 if (dst_as_state != nullptr && src_as_state != nullptr) {
4486 dst_as_state->built = true;
4487 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004488 if (!disabled[command_buffer_state]) {
4489 cb_state->AddChild(dst_as_state);
4490 cb_state->AddChild(src_as_state);
4491 }
sourav parmar35e7a002020-06-09 17:58:44 -07004492 }
4493 }
4494}
Piers Daniell39842ee2020-07-10 16:42:33 -06004495
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004496void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4497 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4498 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4499 if (cb_state) {
4500 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4501 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4502 if (!disabled[command_buffer_state]) {
4503 cb_state->AddChild(src_as_state);
4504 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004505 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4506 if (dst_buffer) {
4507 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004508 }
4509 }
4510}
4511
4512void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4513 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4514 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4515 if (cb_state) {
4516 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4517 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004518 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4519 if (buffer_state) {
4520 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004521 }
4522 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4523 cb_state->AddChild(dst_as_state);
4524 }
4525 }
4526}
4527
Piers Daniell39842ee2020-07-10 16:42:33 -06004528void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004529 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004530 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004531}
4532
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004533void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4534 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4535 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4536}
4537
Piers Daniell39842ee2020-07-10 16:42:33 -06004538void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004539 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004540 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004541}
4542
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004543void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4544 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4545 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4546}
4547
Piers Daniell39842ee2020-07-10 16:42:33 -06004548void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4549 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004550 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004551 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004552 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004553}
4554
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004555void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4556 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004557 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004558 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4559 cb_state->primitiveTopology = primitiveTopology;
4560}
4561
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004562void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4563 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004564 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4565 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004566 uint32_t bits = (1u << viewportCount) - 1u;
4567 cb_state->viewportWithCountMask |= bits;
4568 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004569 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004570 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004571
4572 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4573 for (size_t i = 0; i < viewportCount; ++i) {
4574 cb_state->dynamicViewports[i] = pViewports[i];
4575 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004576}
4577
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004578void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4579 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004580 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004581}
4582
4583void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004584 const VkViewport *pViewports) {
4585 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004586}
4587
4588void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4589 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004590 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004591 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004592 uint32_t bits = (1u << scissorCount) - 1u;
4593 cb_state->scissorWithCountMask |= bits;
4594 cb_state->trashedScissorMask &= ~bits;
4595 cb_state->scissorWithCountCount = scissorCount;
4596 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004597}
4598
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004599void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4600 const VkRect2D *pScissors) {
4601 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4602}
4603
4604void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4605 const VkRect2D *pScissors) {
4606 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4607}
4608
4609void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4610 uint32_t bindingCount, const VkBuffer *pBuffers,
4611 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4612 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004613 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004614 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004615
4616 uint32_t end = firstBinding + bindingCount;
4617 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4618 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4619 }
4620
4621 for (uint32_t i = 0; i < bindingCount; ++i) {
4622 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004623 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004624 vertex_buffer_binding.offset = pOffsets[i];
4625 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4626 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4627 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004628 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004629 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004630 }
4631 }
4632}
4633
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004634void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4635 uint32_t bindingCount, const VkBuffer *pBuffers,
4636 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4637 const VkDeviceSize *pStrides) {
4638 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4639 CMD_BINDVERTEXBUFFERS2EXT);
4640}
4641
4642void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4643 uint32_t bindingCount, const VkBuffer *pBuffers,
4644 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4645 const VkDeviceSize *pStrides) {
4646 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4647 CMD_BINDVERTEXBUFFERS2);
4648}
4649
Piers Daniell39842ee2020-07-10 16:42:33 -06004650void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004651 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004652 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004653}
4654
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004655void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4656 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4657 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4658}
4659
Piers Daniell39842ee2020-07-10 16:42:33 -06004660void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004661 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004662 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004663}
4664
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004665void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4666 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4667 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4668}
4669
Piers Daniell39842ee2020-07-10 16:42:33 -06004670void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004671 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004672 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004673}
4674
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004675void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4676 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4677 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4678}
4679
Piers Daniell39842ee2020-07-10 16:42:33 -06004680void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4681 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004682 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004683 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004684}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004685
4686void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4687 VkBool32 depthBoundsTestEnable) {
4688 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4689 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4690}
4691
Piers Daniell39842ee2020-07-10 16:42:33 -06004692void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004693 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004694 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004695}
4696
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004697void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4698 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4699 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4700}
4701
Piers Daniell39842ee2020-07-10 16:42:33 -06004702void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4703 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4704 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004705 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004706 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004707}
locke-lunarg4189aa22020-10-21 00:23:48 -06004708
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004709void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4710 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4711 VkCompareOp compareOp) {
4712 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4713 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4714}
4715
locke-lunarg4189aa22020-10-21 00:23:48 -06004716void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4717 uint32_t discardRectangleCount,
4718 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004719 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004720 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004721}
4722
4723void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4724 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004725 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004726 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004727}
4728
4729void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4730 VkCoarseSampleOrderTypeNV sampleOrderType,
4731 uint32_t customSampleOrderCount,
4732 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004733 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004734 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004735}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004736
4737void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004738 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004739 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004740}
4741
4742void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004743 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004744 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004745}
4746
4747void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4748 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004749 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004750 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004751 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004752}
4753
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004754void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4755 VkBool32 rasterizerDiscardEnable) {
4756 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4757 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06004758 cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004759}
4760
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004761void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004762 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004763 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004764}
4765
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004766void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4767 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4768 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4769}
4770
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004771void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4772 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004773 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004774 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004775}
Piers Daniell924cd832021-05-18 13:48:47 -06004776
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004777void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4778 VkBool32 primitiveRestartEnable) {
4779 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4780 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4781}
4782
Piers Daniell924cd832021-05-18 13:48:47 -06004783void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4784 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4785 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4786 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004787 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004788 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4789
4790 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4791 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4792 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004793 const auto *dynamic_state = pipeline_state->DynamicState();
4794 if (dynamic_state) {
4795 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4796 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004797 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4798 break;
4799 }
4800 }
4801 }
4802 }
4803 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004804}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004805
ziga-lunarg67b7c392022-03-26 01:45:34 +01004806void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4807 const VkBool32 *pColorWriteEnables) {
4808 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4809 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4810 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4811}
4812
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004813void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004814 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004815 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004816 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004817 // address is used for GPU-AV and ray tracing buffer validation
4818 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004819 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004820 }
4821}
4822
4823void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4824 VkDeviceAddress address) {
4825 RecordGetBufferDeviceAddress(pInfo, address);
4826}
4827
4828void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4829 VkDeviceAddress address) {
4830 RecordGetBufferDeviceAddress(pInfo, address);
4831}
4832
4833void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4834 VkDeviceAddress address) {
4835 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004836}
4837
4838std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4839 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004840 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004841}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004842
4843std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4844 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004845 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004846 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4847}