blob: e077bf1033248fade2c4ff16f06947ff2ce3ea45 [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-LunarG6f887e52021-07-27 11:23:14 -06001223 }
1224
locke-lunargd556cc32019-09-17 01:21:23 -06001225 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001226 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1227 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001228
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001229 {
1230 uint32_t n_props = 0;
1231 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001232 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001233 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001234 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001235
1236 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001237 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001238 }
1239
1240 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1241 // a path to grab that information from the physical device. This
1242 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1243 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001244 has_format_feature2 =
1245 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1246 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001247 }
1248
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001249 const auto &dev_ext = device_extensions;
1250 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001251
Tony-LunarG273f32f2021-09-28 08:56:30 -06001252 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1253 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001254 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1255 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001256 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001257 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001258 } else {
1259 // VkPhysicalDeviceVulkan11Properties
1260 //
1261 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1262
1263 if (dev_ext.vk_khr_multiview) {
1264 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001265 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1266 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1267 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001268 }
1269
1270 if (dev_ext.vk_khr_maintenance3) {
1271 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001272 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1273 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1274 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001275 }
1276
1277 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001278 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001279 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1280 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1281 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001282 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001283
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001284 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1285 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1286 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1287 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001288
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001289 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001290 }
1291
1292 // VkPhysicalDeviceVulkan12Properties
1293 //
1294 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1295
1296 if (dev_ext.vk_ext_descriptor_indexing) {
1297 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001298 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1299 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001300 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001301 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001302 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001303 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001304 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001305 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001307 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001308 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001309 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001310 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001311 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1312 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1313 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001314 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001315 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001316 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001317 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001318 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001319 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001320 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001321 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001322 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001323 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001324 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001325 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001326 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001327 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001328 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001329 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001330 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001331 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001332 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001333 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001334 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001335 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001336 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001337 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001338 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001339 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001340 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001341 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001342 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1343 }
1344
1345 if (dev_ext.vk_khr_depth_stencil_resolve) {
1346 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001347 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1348 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1349 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1350 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1351 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001352 }
1353
1354 if (dev_ext.vk_khr_timeline_semaphore) {
1355 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001356 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1357 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001358 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1359 }
1360
1361 if (dev_ext.vk_ext_sampler_filter_minmax) {
1362 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001363 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1364 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001365 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001366 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001367 }
1368
1369 if (dev_ext.vk_khr_shader_float_controls) {
1370 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001371 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1372 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1373 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1374 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001375 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001376 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001377 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001378 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001379 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001380 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1381 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1382 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1383 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1384 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1385 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1386 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1387 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1388 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1389 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1390 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1391 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001392 }
locke-lunargd556cc32019-09-17 01:21:23 -06001393 }
1394
sfricke-samsung828e59d2021-08-22 23:20:49 -07001395 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001396 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1397 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1398 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1399 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1400 &phys_dev_props->inline_uniform_block_props);
1401 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1402 &phys_dev_props->vtx_attrib_divisor_props);
1403 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1404 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1405 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1406 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1407 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1408 &phys_dev_props->texel_buffer_alignment_props);
1409 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1410 &phys_dev_props->fragment_density_map_props);
1411 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1412 &phys_dev_props->fragment_density_map2_props);
1413 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001414 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001415 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1416 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1417 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1418 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1419 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1420 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1421 &phys_dev_props->fragment_shading_rate_props);
1422 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1423 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1424 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1425 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1426 &phys_dev_props->blend_operation_advanced_props);
1427 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1428 &phys_dev_props->conservative_rasterization_props);
1429 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1430 &phys_dev_props->subgroup_size_control_props);
ziga-lunarge25f5f02022-04-16 15:07:35 +02001431 if (api_version >= VK_API_VERSION_1_1) {
1432 GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_properties);
1433 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001434
sfricke-samsung45996a42021-09-16 13:45:27 -07001435 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001436 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001437 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1438 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001439 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1440 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001441
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001442 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001443 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1444 NULL);
1445 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001446
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001447 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1448 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001449 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001450
locke-lunargd556cc32019-09-17 01:21:23 -06001451 // Store queue family data
1452 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1453 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001454 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001455 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1456 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001457 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001458 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001459 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001460 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1461 VkQueue queue = VK_NULL_HANDLE;
1462 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1463 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1464 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1465 get_info.flags = queue_info.flags;
1466 get_info.queueFamilyIndex = queue_info.queue_family_index;
1467 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001468 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001469 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001470 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001471 }
1472 assert(queue != VK_NULL_HANDLE);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001473 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001474 }
locke-lunargd556cc32019-09-17 01:21:23 -06001475 }
1476 }
1477}
1478
1479void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1480 if (!device) return;
1481
Jeremy Gebbend177d922021-10-28 13:42:10 -06001482 command_pool_map_.clear();
1483 assert(command_buffer_map_.empty());
1484 pipeline_map_.clear();
1485 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001486
1487 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001488 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001489 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001490 assert(descriptor_set_map_.empty());
1491 desc_template_map_.clear();
1492 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001493 // Because swapchains are associated with Surfaces, which are at instance level,
1494 // they need to be explicitly destroyed here to avoid continued references to
1495 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001496 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001497 entry.second->Destroy();
1498 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001499 swapchain_map_.clear();
1500 image_view_map_.clear();
1501 image_map_.clear();
1502 buffer_view_map_.clear();
1503 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001504 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001505 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001506}
1507
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001508void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1509 VkFence fence, VkResult result) {
1510 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001511 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001512
Jeremy Gebben57642982021-09-14 14:14:55 -06001513 uint64_t early_retire_seq = 0;
1514
1515 if (submitCount == 0) {
1516 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001517 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001518 early_retire_seq = queue_state->Submit(std::move(submission));
1519 }
locke-lunargd556cc32019-09-17 01:21:23 -06001520
1521 // Now process each individual submit
1522 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001523 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001524 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001525 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001526 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001527 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001528 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1529 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1530 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1531 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001532 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001533 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001534
locke-lunargd556cc32019-09-17 01:21:23 -06001535 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001536 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001537 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1538 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1539 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1540 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001541 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001542 }
1543
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001544 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001545 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001546
locke-lunargd556cc32019-09-17 01:21:23 -06001547 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001548 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1549 if (cb_state) {
1550 submission.AddCommandBuffer(std::move(cb_state));
1551 }
locke-lunargd556cc32019-09-17 01:21:23 -06001552 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001553 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001554 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001555 }
1556 auto submit_seq = queue_state->Submit(std::move(submission));
1557 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001558 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001559
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001560 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001561 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001562 }
1563}
1564
Tony-LunarG26fe2842021-11-16 14:07:59 -07001565void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1566 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001567 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001568 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001569 uint64_t early_retire_seq = 0;
1570 if (submitCount == 0) {
1571 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001572 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001573 early_retire_seq = queue_state->Submit(std::move(submission));
1574 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001575
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001576 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1577 CB_SUBMISSION submission;
1578 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001579 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1580 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001581 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001582 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001583 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1584 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001585 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001586 }
1587 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1588 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1589
1590 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001591 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001592 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001593 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001594 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001595 }
1596 auto submit_seq = queue_state->Submit(std::move(submission));
1597 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001598 }
locke-lunargd556cc32019-09-17 01:21:23 -06001599 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001600 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001601 }
1602}
1603
Tony-LunarG26fe2842021-11-16 14:07:59 -07001604void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1605 VkFence fence, VkResult result) {
1606 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1607}
1608
1609void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1610 VkFence fence, VkResult result) {
1611 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1612}
1613
locke-lunargd556cc32019-09-17 01:21:23 -06001614void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1615 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1616 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001617 if (VK_SUCCESS != result) {
1618 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001619 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001620 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1621 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1622 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1623
1624 layer_data::optional<DedicatedBinding> dedicated_binding;
1625
1626 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1627 if (dedicated) {
1628 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001629 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001630 assert(buffer_state);
1631 if (!buffer_state) {
1632 return;
1633 }
1634 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1635 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001636 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001637 assert(image_state);
1638 if (!image_state) {
1639 return;
1640 }
1641 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1642 }
1643 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001644 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1645 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001646 return;
1647}
1648
1649void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001650 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001651 if (mem_info) {
1652 fake_memory.Free(mem_info->fake_base_address);
1653 }
1654 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001655}
1656
1657void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1658 VkFence fence, VkResult result) {
1659 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001660 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001661
Jeremy Gebben57642982021-09-14 14:14:55 -06001662 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001663
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001664 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1665 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001666 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001667 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1668 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1669 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001670 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001671 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001672 if (buffer_state) {
1673 buffer_state->BindMemory(buffer_state.get(), mem_state, sparse_binding.memoryOffset,
1674 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001675 }
locke-lunargd556cc32019-09-17 01:21:23 -06001676 }
1677 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001678 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1679 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1680 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001681 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001682 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001683 if (image_state) {
1684 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset,
1685 sparse_binding.resourceOffset, sparse_binding.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001686 }
locke-lunargd556cc32019-09-17 01:21:23 -06001687 }
1688 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001689 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1690 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1691 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001692 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1693 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Aitor Camacho3294edd2022-05-16 22:34:19 +02001694 VkDeviceSize offset = sparse_binding.offset.z * sparse_binding.offset.y * sparse_binding.offset.x * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001695 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001696 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Aitor Camacho3294edd2022-05-16 22:34:19 +02001697 if (image_state) {
1698 image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset, offset, size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001699 }
locke-lunargd556cc32019-09-17 01:21:23 -06001700 }
1701 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001702 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001703 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001704 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001705 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001706 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001707 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001708 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001709 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001710 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001711 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001712 auto submit_seq = queue_state->Submit(std::move(submission));
1713 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001714 }
1715
1716 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001717 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001718 }
1719}
1720
1721void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1722 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1723 VkResult result) {
1724 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001725 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001726}
1727
Mike Schuchardt2df08912020-12-15 16:28:09 -08001728void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1729 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001730 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1731 if (semaphore_state) {
1732 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001733 }
1734}
1735
Mike Schuchardt2df08912020-12-15 16:28:09 -08001736void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001737 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001738 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001739 if (semaphore_state) {
1740 semaphore_state->RetireTimeline(pSignalInfo->value);
1741 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001742}
1743
locke-lunargd556cc32019-09-17 01:21:23 -06001744void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001745 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001746 if (mem_info) {
1747 mem_info->mapped_range.offset = offset;
1748 mem_info->mapped_range.size = size;
1749 mem_info->p_driver_data = *ppData;
1750 }
1751}
1752
locke-lunargd556cc32019-09-17 01:21:23 -06001753void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1754 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1755 if (VK_SUCCESS != result) return;
1756
1757 // When we know that all fences are complete we can clean/remove their CBs
1758 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1759 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001760 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001761 if (fence_state) {
1762 fence_state->Retire();
1763 }
locke-lunargd556cc32019-09-17 01:21:23 -06001764 }
1765 }
1766 // NOTE : Alternate case not handled here is when some fences have completed. In
1767 // this case for app to guarantee which fences completed it will have to call
1768 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1769}
1770
John Zulauff89de662020-04-13 18:57:34 -06001771void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1772 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001773 if (VK_SUCCESS != result) return;
1774
Jeremy Gebben15332642021-12-15 19:33:15 -07001775 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1776 // the application calls vkGetSemaphoreCounterValue() on each of them.
1777 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1778 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1779 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1780 if (semaphore_state) {
1781 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1782 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001783 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001784 }
1785}
1786
John Zulauff89de662020-04-13 18:57:34 -06001787void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1788 VkResult result) {
1789 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1790}
1791
1792void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1793 uint64_t timeout, VkResult result) {
1794 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1795}
1796
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001797void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1798 VkResult result) {
1799 if (VK_SUCCESS != result) return;
1800
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001801 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001802 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001803 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001804 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001805}
1806
1807void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1808 VkResult result) {
1809 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1810}
1811void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1812 VkResult result) {
1813 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1814}
1815
locke-lunargd556cc32019-09-17 01:21:23 -06001816void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1817 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001818 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001819 if (fence_state) {
1820 fence_state->Retire();
1821 }
locke-lunargd556cc32019-09-17 01:21:23 -06001822}
1823
Yilong Lice03a312022-01-02 02:08:35 -08001824void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1825 if (Get<QUEUE_STATE>(queue) == nullptr) {
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001826 Add(CreateQueue(queue, queue_family_index, flags));
Yilong Lice03a312022-01-02 02:08:35 -08001827 }
1828}
1829
1830void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1831 VkQueue *pQueue) {
1832 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1833}
1834
1835void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1836 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1837}
1838
locke-lunargd556cc32019-09-17 01:21:23 -06001839void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1840 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001841 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001842 if (queue_state) {
1843 queue_state->Retire();
1844 }
locke-lunargd556cc32019-09-17 01:21:23 -06001845}
1846
1847void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1848 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001849 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001850 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001851 }
1852}
1853
1854void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001855 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001856}
1857
1858void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1859 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001860 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001861}
1862
1863void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001864 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001865}
1866
1867void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1868 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001869 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001870}
1871
locke-lunargd556cc32019-09-17 01:21:23 -06001872void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001873 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001874 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001875 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001876 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001877 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02001878 buffer_state->BindMemory(buffer_state.get(), mem_state, memoryOffset, 0u, buffer_state->requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001879 }
locke-lunargd556cc32019-09-17 01:21:23 -06001880 }
1881}
1882
1883void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1884 VkDeviceSize memoryOffset, VkResult result) {
1885 if (VK_SUCCESS != result) return;
1886 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1887}
1888
1889void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001890 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001891 for (uint32_t i = 0; i < bindInfoCount; i++) {
1892 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1893 }
1894}
1895
1896void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001897 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001898 for (uint32_t i = 0; i < bindInfoCount; i++) {
1899 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1900 }
1901}
1902
Spencer Fricke6c127102020-04-16 06:25:20 -07001903void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001904 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001905 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001906 buffer_state->memory_requirements_checked = true;
1907 }
1908}
1909
1910void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1911 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001912 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001913}
1914
1915void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001916 const VkBufferMemoryRequirementsInfo2 *pInfo,
1917 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001918 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001919}
1920
1921void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001922 const VkBufferMemoryRequirementsInfo2 *pInfo,
1923 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001924 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001925}
1926
Spencer Fricke6c127102020-04-16 06:25:20 -07001927void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001928 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001929 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001930 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001931 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001932 if (plane_info != nullptr) {
1933 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001934 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001935 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001936 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001937 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001938 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001939 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001940 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001941 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001942 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001943 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001944 }
locke-lunargd556cc32019-09-17 01:21:23 -06001945 }
1946}
1947
1948void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1949 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001950 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001951}
1952
1953void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1954 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001955 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001956}
1957
1958void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1959 const VkImageMemoryRequirementsInfo2 *pInfo,
1960 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001961 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001962}
1963
locke-lunargd556cc32019-09-17 01:21:23 -06001964void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1965 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1966 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001967 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001968 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001969}
1970
1971void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001972 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1973 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001974 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001975 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001976}
1977
1978void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001979 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1980 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001981 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001982 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001983}
1984
1985void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1986 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001987 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001988}
1989
1990void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1991 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001992 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001993}
1994
1995void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1996 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001997 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001998}
1999
2000void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2001 const VkAllocationCallbacks *pAllocator) {
2002 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002003 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002004 // Any bound cmd buffers are now invalid
2005 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002006 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2007 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2008 custom_border_color_sampler_count--;
2009 }
locke-lunargd556cc32019-09-17 01:21:23 -06002010 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06002011 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002012}
2013
2014void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2015 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002016 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06002017}
2018
2019void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2020 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002021 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002022}
2023
locke-lunargd556cc32019-09-17 01:21:23 -06002024void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2025 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002026 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2027 if (pool) {
2028 pool->Free(commandBufferCount, pCommandBuffers);
2029 }
locke-lunargd556cc32019-09-17 01:21:23 -06002030}
2031
2032void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2033 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2034 VkResult result) {
2035 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002036 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002037 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06002038}
2039
2040void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2041 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2042 VkResult result) {
2043 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002044
2045 uint32_t index_count = 0, n_perf_pass = 0;
2046 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002047 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002048 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002049 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002050
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002051 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002052 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2053 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2054 switch (counter.scope) {
2055 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002056 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002057 break;
2058 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002059 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002060 break;
2061 default:
2062 break;
2063 }
2064 }
2065
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002066 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002067 }
2068
Jeremy Gebben082a9832021-10-28 13:40:11 -06002069 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 -06002070
locke-lunargd556cc32019-09-17 01:21:23 -06002071}
2072
2073void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2074 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002075 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002076}
2077
2078void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2079 VkCommandPoolResetFlags flags, VkResult result) {
2080 if (VK_SUCCESS != result) return;
2081 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002082 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2083 if (pool) {
2084 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002085 }
2086}
2087
2088void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2089 VkResult result) {
2090 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002091 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002092 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002093 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002094 }
2095 }
2096}
2097
locke-lunargd556cc32019-09-17 01:21:23 -06002098void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2099 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002100 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002101}
2102
2103void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2104 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002105 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002106}
2107
2108void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2109 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2110 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002111 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002112}
2113
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002114std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2115 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2116 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2117 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2118}
2119
locke-lunargd556cc32019-09-17 01:21:23 -06002120bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2121 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2122 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002123 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002124 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002125 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2126 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2127 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2128 cgpl_state->pipe_state.reserve(count);
2129 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002130 const auto &create_info = pCreateInfos[i];
2131 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2132 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2133
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002134 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002135 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002136 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002137 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2138 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002139 } else {
2140 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2141 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2142 if (!is_graphics_lib && !has_link_info) {
2143 skip = true;
2144 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002145 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002146 cgpl_state->pipe_state.push_back(
2147 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002148 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002149 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002150}
2151
2152void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2153 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2154 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2155 VkResult result, void *cgpl_state_data) {
2156 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2157 // This API may create pipelines regardless of the return value
2158 for (uint32_t i = 0; i < count; i++) {
2159 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002160 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002161 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002162 }
2163 }
2164 cgpl_state->pipe_state.clear();
2165}
2166
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002167std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2168 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2169 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2170}
2171
locke-lunargd556cc32019-09-17 01:21:23 -06002172bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2173 const VkComputePipelineCreateInfo *pCreateInfos,
2174 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002175 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002176 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2177 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2178 ccpl_state->pipe_state.reserve(count);
2179 for (uint32_t i = 0; i < count; i++) {
2180 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002181 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002182 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002183 }
2184 return false;
2185}
2186
2187void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2188 const VkComputePipelineCreateInfo *pCreateInfos,
2189 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2190 VkResult result, void *ccpl_state_data) {
2191 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2192
2193 // This API may create pipelines regardless of the return value
2194 for (uint32_t i = 0; i < count; i++) {
2195 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002196 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002197 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002198 }
2199 }
2200 ccpl_state->pipe_state.clear();
2201}
2202
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002203std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2204 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2205 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2206}
2207
locke-lunargd556cc32019-09-17 01:21:23 -06002208bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2209 uint32_t count,
2210 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2211 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002212 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002213 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2214 crtpl_state->pipe_state.reserve(count);
2215 for (uint32_t i = 0; i < count; i++) {
2216 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002217 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002218 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002219 }
2220 return false;
2221}
2222
2223void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2224 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2225 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2226 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2227 // This API may create pipelines regardless of the return value
2228 for (uint32_t i = 0; i < count; i++) {
2229 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002230 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002231 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002232 }
2233 }
2234 crtpl_state->pipe_state.clear();
2235}
2236
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002237std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2238 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2239 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2240}
2241
sourav parmarcd5fb182020-07-17 12:58:44 -07002242bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2243 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002244 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2245 const VkAllocationCallbacks *pAllocator,
2246 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002247 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002248 crtpl_state->pipe_state.reserve(count);
2249 for (uint32_t i = 0; i < count; i++) {
2250 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002251 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002252 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002253 }
2254 return false;
2255}
2256
sourav parmarcd5fb182020-07-17 12:58:44 -07002257void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2258 VkPipelineCache pipelineCache, uint32_t count,
2259 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2260 const VkAllocationCallbacks *pAllocator,
2261 VkPipeline *pPipelines, VkResult result,
2262 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002263 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002264 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002265 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002266
2267 if (!operation_is_deferred) {
2268 for (uint32_t i = 0; i < count; i++) {
2269 if (pPipelines[i] != VK_NULL_HANDLE) {
2270 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2271 Add(std::move((crtpl_state->pipe_state)[i]));
2272 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002273 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002274 } else {
2275 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2276 if (wrap_handles) {
2277 deferredOperation = layer_data->Unwrap(deferredOperation);
2278 }
2279 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2280 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2281 if (find_res->first) {
2282 cleanup_fn = std::move(find_res->second);
2283 }
2284 auto &pipeline_states = crtpl_state->pipe_state;
2285 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2286 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2287 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2288 pipeline_states[i]->SetHandle(pipelines[i]);
2289 this->Add(std::move(pipeline_states[i]));
2290 }
2291 });
2292 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002293 }
2294 crtpl_state->pipe_state.clear();
2295}
2296
locke-lunargd556cc32019-09-17 01:21:23 -06002297void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2298 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2299 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002300 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002301 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2302 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002303 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002304 }
locke-lunargd556cc32019-09-17 01:21:23 -06002305}
2306
2307void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2308 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2309 const VkAllocationCallbacks *pAllocator,
2310 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2311 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002312 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002313}
2314
locke-lunargd556cc32019-09-17 01:21:23 -06002315void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2316 const VkAllocationCallbacks *pAllocator,
2317 VkPipelineLayout *pPipelineLayout, VkResult result) {
2318 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002319 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002320}
2321
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002322std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2323 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2324 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2325}
2326
locke-lunargd556cc32019-09-17 01:21:23 -06002327void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2328 const VkAllocationCallbacks *pAllocator,
2329 VkDescriptorPool *pDescriptorPool, VkResult result) {
2330 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002331 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002332}
2333
2334void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2335 VkDescriptorPoolResetFlags flags, VkResult result) {
2336 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002337 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2338 if (pool) {
2339 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002340 }
locke-lunargd556cc32019-09-17 01:21:23 -06002341}
2342
2343bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2344 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002345 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002346 // Always update common data
2347 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2348 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2349 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2350
2351 return false;
2352}
2353
2354// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2355void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2356 VkDescriptorSet *pDescriptorSets, VkResult result,
2357 void *ads_state_data) {
2358 if (VK_SUCCESS != result) return;
2359 // All the updates are contained in a single cvdescriptorset function
2360 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2361 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002362 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2363 if (pool_state) {
2364 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2365 }
locke-lunargd556cc32019-09-17 01:21:23 -06002366}
2367
2368void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2369 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002370 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2371 if (pool_state) {
2372 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002373 }
2374}
2375
2376void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2377 const VkWriteDescriptorSet *pDescriptorWrites,
2378 uint32_t descriptorCopyCount,
2379 const VkCopyDescriptorSet *pDescriptorCopies) {
2380 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2381 pDescriptorCopies);
2382}
2383
2384void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002385 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002386 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002387 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002388 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002389 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002390 }
2391}
2392
locke-lunargd556cc32019-09-17 01:21:23 -06002393void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2394 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002395 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002396 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002397
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002398 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002399}
2400
2401void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002402 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002403 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002404
2405 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002406}
2407
2408void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2409 VkResult result) {
2410 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002411 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2412 if (cb_state) {
2413 cb_state->Reset();
2414 }
locke-lunargd556cc32019-09-17 01:21:23 -06002415 }
2416}
2417
2418CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2419 // initially assume everything is static state
2420 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2421
2422 if (ds) {
2423 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002424 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002425 }
2426 }
locke-lunargd556cc32019-09-17 01:21:23 -06002427 return flags;
2428}
2429
2430// Validation cache:
2431// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002432
2433void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2434 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002435 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002436 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002437 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002438
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002439 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002440 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002441 const auto *raster_state = pipe_state->RasterizationState();
2442 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002443 const auto *viewport_state = pipe_state->ViewportState();
2444 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002445 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002446 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002447 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002448 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002449
2450 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002451 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2452 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002453 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002454 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002455 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002456 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002457 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002458 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002459
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002460 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002461 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2462 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2463 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002464 if (!has_dynamic_viewport_count) {
2465 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002466 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002467 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2468 // should become = ~uint32_t(0) if the other interpretation is correct.
2469 }
2470 }
2471 if (!has_dynamic_scissor_count) {
2472 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002473 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002474 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2475 // should become = ~uint32_t(0) if the other interpretation is correct.
2476 }
2477 }
locke-lunargd556cc32019-09-17 01:21:23 -06002478 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002479 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002480 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002481 if (!disabled[command_buffer_state]) {
2482 cb_state->AddChild(pipe_state);
2483 }
locke-lunargd556cc32019-09-17 01:21:23 -06002484}
2485
2486void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2487 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002488 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002489 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002490 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2491 cb_state->viewportMask |= bits;
2492 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002493
2494 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2495 for (size_t i = 0; i < viewportCount; ++i) {
2496 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2497 }
locke-lunargd556cc32019-09-17 01:21:23 -06002498}
2499
2500void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2501 uint32_t exclusiveScissorCount,
2502 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002503 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002504 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002505 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2506 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002507}
2508
2509void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2510 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002511 if (disabled[command_buffer_state]) return;
2512
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002513 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002514 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002515
2516 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002517 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002518 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002519 }
2520}
2521
2522void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2523 uint32_t viewportCount,
2524 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002525 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002526 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002527 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2528 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002529}
2530
2531void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2532 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2533 const VkAllocationCallbacks *pAllocator,
2534 VkAccelerationStructureNV *pAccelerationStructure,
2535 VkResult result) {
2536 if (VK_SUCCESS != result) return;
Aitor Camacho3294edd2022-05-16 22:34:19 +02002537 std::shared_ptr<ACCELERATION_STRUCTURE_STATE> state =
2538 std::make_shared<ACCELERATION_STRUCTURE_STATE_LINEAR>(device, *pAccelerationStructure, pCreateInfo);
2539 Add(std::move(state));
locke-lunargd556cc32019-09-17 01:21:23 -06002540}
2541
Jeff Bolz95176d02020-04-01 00:36:16 -05002542void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2543 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2544 const VkAllocationCallbacks *pAllocator,
2545 VkAccelerationStructureKHR *pAccelerationStructure,
2546 VkResult result) {
2547 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002548 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2549 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002550}
2551
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002552void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2553 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2554 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2555 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2556 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002557 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002558 if (dst_as_state != nullptr) {
2559 dst_as_state->Build(&pInfos[i]);
2560 }
2561 }
2562}
2563
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002564// helper method for device side acceleration structure builds
2565void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2566 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2567 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2568 if (dst_as_state) {
2569 dst_as_state->Build(&info);
2570 }
2571 if (disabled[command_buffer_state]) {
2572 return;
2573 }
2574 if (dst_as_state) {
2575 cb_state.AddChild(dst_as_state);
2576 }
2577 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2578 if (src_as_state) {
2579 cb_state.AddChild(src_as_state);
2580 }
2581 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2582 if (scratch_buffer) {
2583 cb_state.AddChild(scratch_buffer);
2584 }
2585
2586 for (uint32_t i = 0; i < info.geometryCount; i++) {
2587 // only one of pGeometries and ppGeometries can be non-null
2588 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2589 switch (geom.geometryType) {
2590 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2591 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2592 if (vertex_buffer) {
2593 cb_state.AddChild(vertex_buffer);
2594 }
2595 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2596 if (index_buffer) {
2597 cb_state.AddChild(index_buffer);
2598 }
2599 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2600 if (transform_buffer) {
2601 cb_state.AddChild(transform_buffer);
2602 }
2603 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2604 if (motion_data) {
2605 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2606 if (motion_buffer) {
2607 cb_state.AddChild(motion_buffer);
2608 }
2609 }
2610 } break;
2611 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2612 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2613 if (data_buffer) {
2614 cb_state.AddChild(data_buffer);
2615 }
2616 } break;
2617 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2618 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2619 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2620 // easily ensure that's true.
2621 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2622 if (data_buffer) {
2623 cb_state.AddChild(data_buffer);
2624 }
2625 } break;
2626 default:
2627 break;
2628 }
2629 }
2630}
2631
sourav parmarcd5fb182020-07-17 12:58:44 -07002632void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2633 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2634 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002635 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002636 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002637 return;
2638 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002639 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002640 for (uint32_t i = 0; i < infoCount; i++) {
2641 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002642 }
2643 cb_state->hasBuildAccelerationStructureCmd = true;
2644}
2645
2646void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2647 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2648 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2649 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002650 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2651 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002652 return;
2653 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002654 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002655 for (uint32_t i = 0; i < infoCount; i++) {
2656 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002657 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002658 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2659 if (indirect_buffer) {
2660 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002661 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002662 }
2663 }
2664 cb_state->hasBuildAccelerationStructureCmd = true;
2665}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002666
locke-lunargd556cc32019-09-17 01:21:23 -06002667void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002668 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002669 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002670 if (as_state != nullptr) {
2671 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002672 as_state->memory_requirements_checked = true;
2673 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002674 as_state->build_scratch_memory_requirements_checked = true;
2675 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002676 as_state->update_scratch_memory_requirements_checked = true;
2677 }
2678 }
2679}
2680
sourav parmarcd5fb182020-07-17 12:58:44 -07002681void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2682 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002683 if (VK_SUCCESS != result) return;
2684 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002685 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002686
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002687 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002688 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002689 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002690 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002691 if (mem_state) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02002692 as_state->BindMemory(as_state.get(), mem_state, info.memoryOffset, 0u, as_state->memory_requirements.size);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002693 }
locke-lunargd556cc32019-09-17 01:21:23 -06002694
2695 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002696 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002697 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002698 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2699 }
2700 }
2701 }
2702}
2703
2704void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2705 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2706 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002707 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2708 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002709 return;
2710 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002711 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002712
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002713 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002714 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002715 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002716 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002717 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002718 }
locke-lunargd556cc32019-09-17 01:21:23 -06002719 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002720 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002721 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002722 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002723 cb_state->AddChild(src_as_state);
2724 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002725 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2726 if (instance_buffer) {
2727 cb_state->AddChild(instance_buffer);
2728 }
2729 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2730 if (scratch_buffer) {
2731 cb_state->AddChild(scratch_buffer);
2732 }
2733
2734 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2735 const auto& geom = pInfo->pGeometries[i];
2736
2737 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2738 if (vertex_buffer) {
2739 cb_state->AddChild(vertex_buffer);
2740 }
2741 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2742 if (index_buffer) {
2743 cb_state->AddChild(index_buffer);
2744 }
2745 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2746 if (transform_buffer) {
2747 cb_state->AddChild(transform_buffer);
2748 }
2749
2750 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2751 if (aabb_buffer) {
2752 cb_state->AddChild(aabb_buffer);
2753 }
2754 }
2755
locke-lunargd556cc32019-09-17 01:21:23 -06002756 }
2757 cb_state->hasBuildAccelerationStructureCmd = true;
2758}
2759
2760void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2761 VkAccelerationStructureNV dst,
2762 VkAccelerationStructureNV src,
2763 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002764 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002765 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002766 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2767 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002768 if (!disabled[command_buffer_state]) {
2769 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2770 }
locke-lunargd556cc32019-09-17 01:21:23 -06002771 if (dst_as_state != nullptr && src_as_state != nullptr) {
2772 dst_as_state->built = true;
2773 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002774 }
2775 }
2776}
2777
Jeff Bolz95176d02020-04-01 00:36:16 -05002778void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2779 VkAccelerationStructureKHR accelerationStructure,
2780 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002781 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002782}
2783
Jeff Bolz95176d02020-04-01 00:36:16 -05002784void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2785 VkAccelerationStructureNV accelerationStructure,
2786 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002787 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002788}
2789
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002790void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2791 uint32_t viewportCount,
2792 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002793 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002794 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002795}
2796
locke-lunargd556cc32019-09-17 01:21:23 -06002797void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002798 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002799 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002800}
2801
2802void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2803 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002804 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002805 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002806}
2807
2808void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2809 float depthBiasClamp, float depthBiasSlopeFactor) {
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_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002812}
2813
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002814void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2815 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002816 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002817 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002818 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2819 cb_state->scissorMask |= bits;
2820 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002821}
2822
locke-lunargd556cc32019-09-17 01:21:23 -06002823void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002824 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002825 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002826}
2827
2828void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2829 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002830 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002831 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002832}
2833
2834void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2835 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002836 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002837 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002838}
2839
2840void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2841 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002842 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002843 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002844}
2845
2846void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2847 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002848 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002849 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002850}
2851
locke-lunargd556cc32019-09-17 01:21:23 -06002852// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2853void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2854 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2855 uint32_t firstSet, uint32_t setCount,
2856 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2857 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002858 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002859 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002860 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002861 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002862
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002863 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2864 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002865}
2866
locke-lunargd556cc32019-09-17 01:21:23 -06002867void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2868 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2869 uint32_t set, uint32_t descriptorWriteCount,
2870 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002871 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002872 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002873 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002874}
2875
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002876void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2877 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2878 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002879 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2880 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002881 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002882 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2883 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002884
2885 auto &push_constant_data = cb_state->push_constant_data;
2886 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2887 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002888 cb_state->push_constant_pipeline_layout_set = layout;
2889
2890 auto flags = stageFlags;
2891 uint32_t bit_shift = 0;
2892 while (flags) {
2893 if (flags & 1) {
2894 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2895 const auto it = cb_state->push_constant_data_update.find(flag);
2896
2897 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002898 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002899 }
2900 }
2901 flags = flags >> 1;
2902 ++bit_shift;
2903 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002904 }
2905}
2906
locke-lunargd556cc32019-09-17 01:21:23 -06002907void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2908 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002909 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002910
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002911 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002912 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002913 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002914 cb_state->index_buffer_binding.offset = offset;
2915 cb_state->index_buffer_binding.index_type = indexType;
2916 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002917 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002918 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002919 }
locke-lunargd556cc32019-09-17 01:21:23 -06002920}
2921
2922void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2923 uint32_t bindingCount, const VkBuffer *pBuffers,
2924 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002925 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002926 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002927
2928 uint32_t end = firstBinding + bindingCount;
2929 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2930 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2931 }
2932
2933 for (uint32_t i = 0; i < bindingCount; ++i) {
2934 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002935 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002936 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002937 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2938 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002939 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002940 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002941 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002942 }
locke-lunargd556cc32019-09-17 01:21:23 -06002943 }
2944}
2945
2946void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2947 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002948 if (disabled[command_buffer_state]) return;
2949
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002950 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002951 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002952}
2953
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002954void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2955 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002956 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002957 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002958}
2959
2960void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2961 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002962 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002963 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2964
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002965 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2966 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002967}
2968
Tony-LunarGc43525f2021-11-15 16:12:38 -07002969void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2970 const VkDependencyInfo* pDependencyInfo) {
2971 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2972 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2973
2974 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2975 cb_state->RecordBarriers(*pDependencyInfo);
2976}
2977
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002978void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2979 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002980 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002981 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002982}
2983
2984void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2985 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002986 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002987 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002988}
2989
Tony-LunarGa2662db2021-11-16 07:26:24 -07002990void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2991 VkPipelineStageFlags2 stageMask) {
2992 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2993 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2994}
2995
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002996void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2997 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2998 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2999 uint32_t bufferMemoryBarrierCount,
3000 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3001 uint32_t imageMemoryBarrierCount,
3002 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003003 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3004 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003005 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3006 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003007}
3008
3009void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3010 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003011 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06003012 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003013 const auto &dep_info = pDependencyInfos[i];
3014 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3015 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
3016 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06003017 }
3018}
3019
Tony-LunarG1364cf52021-11-17 16:10:11 -07003020void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3021 const VkDependencyInfo *pDependencyInfos) {
3022 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3023 for (uint32_t i = 0; i < eventCount; i++) {
3024 const auto &dep_info = pDependencyInfos[i];
3025 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
3026 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
3027 cb_state->RecordBarriers(dep_info);
3028 }
3029}
3030
Jeremy Gebben79649152021-06-22 14:46:24 -06003031void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3032 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3033 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3034 uint32_t bufferMemoryBarrierCount,
3035 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3036 uint32_t imageMemoryBarrierCount,
3037 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003038 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003039 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3040 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3041 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003042}
3043
3044void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3045 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003046 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003047 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3048 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003049}
3050
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07003051void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
3052 const VkDependencyInfo *pDependencyInfo) {
3053 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3054 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
3055 cb_state->RecordBarriers(*pDependencyInfo);
3056}
3057
locke-lunargd556cc32019-09-17 01:21:23 -06003058void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3059 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003060 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003061
locke-lunargd556cc32019-09-17 01:21:23 -06003062 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003063 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003064 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003065 if (!disabled[query_validation]) {
3066 cb_state->BeginQuery(query);
3067 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003068 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003069 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003070 cb_state->AddChild(pool_state);
3071 }
locke-lunargd556cc32019-09-17 01:21:23 -06003072}
3073
3074void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003075 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003076 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003077 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003078 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003079 if (!disabled[query_validation]) {
3080 cb_state->EndQuery(query_obj);
3081 }
3082 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003083 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003084 cb_state->AddChild(pool_state);
3085 }
locke-lunargd556cc32019-09-17 01:21:23 -06003086}
3087
3088void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3089 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003090 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003091 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003092
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003093 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003094 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003095
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003096 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003097 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003098 cb_state->AddChild(pool_state);
3099 }
locke-lunargd556cc32019-09-17 01:21:23 -06003100}
3101
3102void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3103 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3104 VkDeviceSize dstOffset, VkDeviceSize stride,
3105 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003106 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3107
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003108 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003109 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003110 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003111 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003112 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003113 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003114}
3115
3116void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3117 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003118 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003119 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003120}
3121
3122void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3123 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3124 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003125 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003126 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003127}
3128
Tony-LunarGde9936b2021-11-17 15:34:11 -07003129void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3130 VkQueryPool queryPool, uint32_t slot) {
3131 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3132 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3133}
3134
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003135void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3136 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3137 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3138 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003139 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003140 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003141 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003142 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003143 cb_state->AddChild(pool_state);
3144 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003145 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003146}
3147
locke-lunargd556cc32019-09-17 01:21:23 -06003148void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3149 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3150 VkResult result) {
3151 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003152
Jeremy Gebben88f58142021-06-01 10:07:52 -06003153 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003154 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003155 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003156
locke-lunargd556cc32019-09-17 01:21:23 -06003157 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003158 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003159 }
3160 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003161
Jeremy Gebben9f537102021-10-05 16:37:12 -06003162 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003163 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003164}
3165
locke-lunargd556cc32019-09-17 01:21:23 -06003166void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3167 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3168 VkResult result) {
3169 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003170 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003171}
3172
Mike Schuchardt2df08912020-12-15 16:28:09 -08003173void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003174 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3175 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003176 if (VK_SUCCESS != result) return;
3177
Jeremy Gebben082a9832021-10-28 13:40:11 -06003178 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003179}
3180
Mike Schuchardt2df08912020-12-15 16:28:09 -08003181void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003182 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3183 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003184 if (VK_SUCCESS != result) return;
3185
Jeremy Gebben082a9832021-10-28 13:40:11 -06003186 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003187}
3188
locke-lunargd556cc32019-09-17 01:21:23 -06003189void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3190 const VkRenderPassBeginInfo *pRenderPassBegin,
3191 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003192 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003193 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003194}
3195
3196void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3197 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003198 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003199 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003200 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003201}
3202
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003203void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3204 uint32_t counterBufferCount,
3205 const VkBuffer *pCounterBuffers,
3206 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003207 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003208
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003209 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003210 cb_state->transform_feedback_active = true;
3211}
3212
3213void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3214 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3215 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003216 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003217
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003218 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003219 cb_state->transform_feedback_active = false;
3220}
3221
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003222void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3223 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003224 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003225
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003226 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003227 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003228 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3229 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003230}
3231
3232void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003233 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003234
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003235 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003236 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003237 cb_state->conditional_rendering_inside_render_pass = false;
3238 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003239}
3240
amhagana448ea52021-11-02 14:09:14 -04003241void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003242 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003243 cb_state->activeRenderPass = nullptr;
3244}
3245
3246void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3247 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003248 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003249 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3250}
3251
Tony-LunarG40b33882021-12-02 12:40:11 -07003252void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3253 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3254 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3255}
3256
amhagana448ea52021-11-02 14:09:14 -04003257void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3258 RecordCmdEndRenderingRenderPassState(commandBuffer);
3259}
3260
Tony-LunarG40b33882021-12-02 12:40:11 -07003261void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3262 RecordCmdEndRenderingRenderPassState(commandBuffer);
3263}
3264
Tony-LunarG977448c2019-12-02 14:52:02 -07003265void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3266 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003267 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003268 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003269 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003270}
3271
locke-lunargd556cc32019-09-17 01:21:23 -06003272void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003273 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003274 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003275}
3276
3277void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003278 const VkSubpassBeginInfo *pSubpassBeginInfo,
3279 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003280 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003281 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003282}
3283
Tony-LunarG977448c2019-12-02 14:52:02 -07003284void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003285 const VkSubpassBeginInfo *pSubpassBeginInfo,
3286 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003287 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003288 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003289}
3290
3291void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003292 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003293 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003294}
3295
3296void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003297 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003298 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003299 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003300}
3301
Tony-LunarG977448c2019-12-02 14:52:02 -07003302void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003303 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->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003306}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003307
locke-lunargd556cc32019-09-17 01:21:23 -06003308void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3309 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003310 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003311
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003312 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003313}
3314
3315void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3316 VkFlags flags, void **ppData, VkResult result) {
3317 if (VK_SUCCESS != result) return;
3318 RecordMappedMemory(mem, offset, size, ppData);
3319}
3320
3321void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003322 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003323 if (mem_info) {
3324 mem_info->mapped_range = MemRange();
3325 mem_info->p_driver_data = nullptr;
3326 }
3327}
3328
3329void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003330 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003331 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003332 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3333 // See: VUID-vkGetImageSubresourceLayout-image-01895
3334 image_state->fragment_encoder =
3335 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003336 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003337 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003338 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003339 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003340 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003341
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003342 if (!swapchain_image.fake_base_address) {
3343 auto size = image_state->fragment_encoder->TotalSize();
3344 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003345 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003346 // All images bound to this swapchain and index are aliases
3347 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003348 }
3349 } else {
3350 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003351 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003352 if (mem_info) {
Aitor Camacho3294edd2022-05-16 22:34:19 +02003353 VkDeviceSize plane_index = 0u;
3354 if (image_state->disjoint && image_state->IsExternalAHB() == false) {
3355 auto plane_info = LvlFindInChain<VkBindImagePlaneMemoryInfo>(bindInfo.pNext);
3356 const VkImageAspectFlagBits aspect = plane_info->planeAspect;
3357 switch (aspect) {
3358 case VK_IMAGE_ASPECT_PLANE_0_BIT:
3359 plane_index = 0;
3360 break;
3361 case VK_IMAGE_ASPECT_PLANE_1_BIT:
3362 plane_index = 1;
3363 break;
3364 case VK_IMAGE_ASPECT_PLANE_2_BIT:
3365 plane_index = 2;
3366 break;
3367 default:
3368 assert(false); // parameter validation should have caught this
3369 break;
3370 }
3371 }
3372 image_state->BindMemory(
3373 image_state.get(), mem_info, bindInfo.memoryOffset, plane_index,
3374 image_state->requirements[static_cast<decltype(image_state->requirements)::size_type>(plane_index)].size);
locke-lunargd556cc32019-09-17 01:21:23 -06003375 }
locke-lunargd556cc32019-09-17 01:21:23 -06003376 }
locke-lunargd556cc32019-09-17 01:21:23 -06003377 }
3378}
3379
3380void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3381 VkDeviceSize memoryOffset, VkResult result) {
3382 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003383 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003384 bind_info.image = image;
3385 bind_info.memory = mem;
3386 bind_info.memoryOffset = memoryOffset;
3387 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003388}
3389
3390void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003391 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003392 if (VK_SUCCESS != result) return;
3393 for (uint32_t i = 0; i < bindInfoCount; i++) {
3394 UpdateBindImageMemoryState(pBindInfos[i]);
3395 }
3396}
3397
3398void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003399 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003400 if (VK_SUCCESS != result) return;
3401 for (uint32_t i = 0; i < bindInfoCount; i++) {
3402 UpdateBindImageMemoryState(pBindInfos[i]);
3403 }
3404}
3405
3406void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003407 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003408 if (event_state) {
3409 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3410 }
locke-lunargd556cc32019-09-17 01:21:23 -06003411}
3412
3413void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3414 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3415 VkResult result) {
3416 if (VK_SUCCESS != result) return;
3417 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3418 pImportSemaphoreFdInfo->flags);
3419}
3420
3421void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003422 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003423 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003424 if (semaphore_state) {
3425 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003426 }
3427}
3428
3429#ifdef VK_USE_PLATFORM_WIN32_KHR
3430void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3431 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3432 if (VK_SUCCESS != result) return;
3433 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3434 pImportSemaphoreWin32HandleInfo->flags);
3435}
3436
3437void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3438 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3439 HANDLE *pHandle, VkResult result) {
3440 if (VK_SUCCESS != result) return;
3441 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3442}
3443
3444void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3445 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3446 if (VK_SUCCESS != result) return;
3447 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3448 pImportFenceWin32HandleInfo->flags);
3449}
3450
3451void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3452 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3453 HANDLE *pHandle, VkResult result) {
3454 if (VK_SUCCESS != result) return;
3455 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3456}
3457#endif
3458
3459void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3460 VkResult result) {
3461 if (VK_SUCCESS != result) return;
3462 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3463}
3464
Mike Schuchardt2df08912020-12-15 16:28:09 -08003465void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3466 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003467 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003468
3469 if (fence_node) {
3470 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003471 }
3472}
3473
3474void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3475 VkResult result) {
3476 if (VK_SUCCESS != result) return;
3477 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3478}
3479
Mike Schuchardt2df08912020-12-15 16:28:09 -08003480void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003481 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003482 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003483 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003484 }
3485}
3486
3487void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3488 VkResult result) {
3489 if (VK_SUCCESS != result) return;
3490 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3491}
3492
3493void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3494 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3495 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003496 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003497}
3498
3499void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003500 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003501 SWAPCHAIN_NODE *old_swapchain_state) {
3502 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003503 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003504 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003505 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003506 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3507 surface_state->AddParent(swapchain.get());
3508 surface_state->swapchain = swapchain.get();
3509 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003510 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003511 } else {
3512 surface_state->swapchain = nullptr;
3513 }
3514 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003515 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003516 if (old_swapchain_state) {
3517 old_swapchain_state->retired = true;
3518 }
3519 return;
3520}
3521
3522void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3523 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3524 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003525 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003526 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003527 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003528}
3529
3530void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3531 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003532 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003533}
3534
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003535void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3536 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3537 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3538 VkResult result) {
3539 if (VK_SUCCESS != result) return;
3540 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003541 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003542}
3543
locke-lunargd556cc32019-09-17 01:21:23 -06003544void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003545 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003546 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003547 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3548 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3549 if (semaphore_state) {
3550 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003551 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003552 }
3553
3554 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3555 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3556 // 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
3557 // confused itself just as much.
3558 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3559 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3560 // Mark the image as having been released to the WSI
3561 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3562 if (swapchain_data) {
3563 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3564 if (present_id_info) {
3565 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3566 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3567 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003568 }
3569 }
locke-lunargd556cc32019-09-17 01:21:23 -06003570 }
locke-lunargd556cc32019-09-17 01:21:23 -06003571}
3572
3573void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3574 const VkSwapchainCreateInfoKHR *pCreateInfos,
3575 const VkAllocationCallbacks *pAllocator,
3576 VkSwapchainKHR *pSwapchains, VkResult result) {
3577 if (pCreateInfos) {
3578 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003579 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003580 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003581 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3582 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003583 }
3584 }
3585}
3586
3587void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3588 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003589 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003590 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003591 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3592 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003593 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003594 }
3595
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003596 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003597 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003598 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3599 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003600 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003601 }
3602
3603 // Mark the image as acquired.
3604 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3605 if (swapchain_data) {
3606 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003607 }
3608}
3609
3610void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3611 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3612 VkResult result) {
3613 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3614 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3615}
3616
3617void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3618 uint32_t *pImageIndex, VkResult result) {
3619 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3620 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3621 pAcquireInfo->fence, pImageIndex);
3622}
3623
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003624std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3625 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3626}
3627
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003628void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3629 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3630 VkResult result) {
3631 if (result != VK_SUCCESS) {
3632 return;
3633 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003634 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003635 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003636 // this can fail if the allocator fails
3637 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3638 if (result != VK_SUCCESS) {
3639 return;
3640 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003641 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003642 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3643 if (result != VK_SUCCESS) {
3644 return;
3645 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003646
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003647 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003648 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003649 }
3650}
3651
3652// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003653static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003654 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003655}
3656
3657void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3658 uint32_t *pQueueFamilyPropertyCount,
3659 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003660 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3661 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003662 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003663}
3664
3665void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003666 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003667 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3668 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003669 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003670}
3671
3672void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003673 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003674 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3675 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003676 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003677}
3678void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3679 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003680 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003681}
3682
Jeremy Gebben082a9832021-10-28 13:40:11 -06003683void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003684
3685void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3686 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3687 const VkAllocationCallbacks *pAllocator,
3688 VkSurfaceKHR *pSurface, VkResult result) {
3689 if (VK_SUCCESS != result) return;
3690 RecordVulkanSurface(pSurface);
3691}
3692
3693#ifdef VK_USE_PLATFORM_ANDROID_KHR
3694void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3695 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3696 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3697 VkResult result) {
3698 if (VK_SUCCESS != result) return;
3699 RecordVulkanSurface(pSurface);
3700}
3701#endif // VK_USE_PLATFORM_ANDROID_KHR
3702
3703#ifdef VK_USE_PLATFORM_IOS_MVK
3704void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3705 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3706 VkResult result) {
3707 if (VK_SUCCESS != result) return;
3708 RecordVulkanSurface(pSurface);
3709}
3710#endif // VK_USE_PLATFORM_IOS_MVK
3711
3712#ifdef VK_USE_PLATFORM_MACOS_MVK
3713void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3714 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3715 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3716 VkResult result) {
3717 if (VK_SUCCESS != result) return;
3718 RecordVulkanSurface(pSurface);
3719}
3720#endif // VK_USE_PLATFORM_MACOS_MVK
3721
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003722#ifdef VK_USE_PLATFORM_METAL_EXT
3723void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3724 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3725 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3726 VkResult result) {
3727 if (VK_SUCCESS != result) return;
3728 RecordVulkanSurface(pSurface);
3729}
3730#endif // VK_USE_PLATFORM_METAL_EXT
3731
locke-lunargd556cc32019-09-17 01:21:23 -06003732#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3733void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3734 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3735 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3736 VkResult result) {
3737 if (VK_SUCCESS != result) return;
3738 RecordVulkanSurface(pSurface);
3739}
3740#endif // VK_USE_PLATFORM_WAYLAND_KHR
3741
3742#ifdef VK_USE_PLATFORM_WIN32_KHR
3743void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3744 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3745 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3746 VkResult result) {
3747 if (VK_SUCCESS != result) return;
3748 RecordVulkanSurface(pSurface);
3749}
3750#endif // VK_USE_PLATFORM_WIN32_KHR
3751
3752#ifdef VK_USE_PLATFORM_XCB_KHR
3753void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3754 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3755 VkResult result) {
3756 if (VK_SUCCESS != result) return;
3757 RecordVulkanSurface(pSurface);
3758}
3759#endif // VK_USE_PLATFORM_XCB_KHR
3760
3761#ifdef VK_USE_PLATFORM_XLIB_KHR
3762void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3763 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3764 VkResult result) {
3765 if (VK_SUCCESS != result) return;
3766 RecordVulkanSurface(pSurface);
3767}
3768#endif // VK_USE_PLATFORM_XLIB_KHR
3769
Niklas Haas8b84af12020-04-19 22:20:11 +02003770void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3771 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3772 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3773 VkResult result) {
3774 if (VK_SUCCESS != result) return;
3775 RecordVulkanSurface(pSurface);
3776}
3777
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003778void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3779 VkSurfaceKHR surface,
3780 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3781 VkResult result) {
3782 if (VK_SUCCESS != result) return;
3783 auto surface_state = Get<SURFACE_STATE>(surface);
3784 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3785}
3786
3787void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3788 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3789 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3790 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003791
3792 if (pSurfaceInfo->surface) {
3793 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3794 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3795 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3796 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3797 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3798 assert(pd_state);
3799 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3800 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003801}
3802
3803void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3804 VkSurfaceKHR surface,
3805 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3806 VkResult result) {
3807 auto surface_state = Get<SURFACE_STATE>(surface);
3808 VkSurfaceCapabilitiesKHR caps{
3809 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3810 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3811 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3812 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3813 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3814 };
3815 surface_state->SetCapabilities(physicalDevice, caps);
3816}
3817
locke-lunargd556cc32019-09-17 01:21:23 -06003818void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3819 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3820 VkBool32 *pSupported, VkResult result) {
3821 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003822 auto surface_state = Get<SURFACE_STATE>(surface);
3823 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3824}
3825
3826void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3827 VkSurfaceKHR surface,
3828 uint32_t *pPresentModeCount,
3829 VkPresentModeKHR *pPresentModes,
3830 VkResult result) {
3831 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3832
3833 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003834 if (surface) {
3835 auto surface_state = Get<SURFACE_STATE>(surface);
3836 surface_state->SetPresentModes(physicalDevice,
3837 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3838 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3839 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3840 assert(pd_state);
3841 pd_state->surfaceless_query_state.present_modes =
3842 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3843 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003844 }
3845}
3846
3847void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3848 uint32_t *pSurfaceFormatCount,
3849 VkSurfaceFormatKHR *pSurfaceFormats,
3850 VkResult result) {
3851 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3852
3853 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003854 if (surface) {
3855 auto surface_state = Get<SURFACE_STATE>(surface);
3856 surface_state->SetFormats(physicalDevice,
3857 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3858 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3859 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3860 assert(pd_state);
3861 pd_state->surfaceless_query_state.formats =
3862 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3863 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003864 }
3865}
3866
3867void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3868 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3869 uint32_t *pSurfaceFormatCount,
3870 VkSurfaceFormat2KHR *pSurfaceFormats,
3871 VkResult result) {
3872 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3873
3874 if (pSurfaceFormats) {
3875 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003876 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3877 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3878 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003879 if (pSurfaceInfo->surface) {
3880 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3881 surface_state->SetFormats(physicalDevice, std::move(fmts));
3882 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3883 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3884 assert(pd_state);
3885 pd_state->surfaceless_query_state.formats = std::move(fmts);
3886 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003887 }
locke-lunargd556cc32019-09-17 01:21:23 -06003888}
3889
locke-lunargd556cc32019-09-17 01:21:23 -06003890void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3891 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003892 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003893 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003894 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3895}
3896
3897void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003898 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003899 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003900 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3901}
3902
3903void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3904 const VkDebugUtilsLabelEXT *pLabelInfo) {
3905 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3906
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003907 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003908 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3909 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003910 cb_state->debug_label = LoggingLabel(pLabelInfo);
3911}
3912
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003913void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3914 uint32_t queueFamilyIndex,
3915 uint32_t *pCounterCount,
3916 VkPerformanceCounterKHR *pCounters) {
3917 if (NULL == pCounters) return;
3918
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003919 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3920 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003921
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003922 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3923 queue_family_counters->counters.resize(*pCounterCount);
3924 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003925
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003926 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003927}
3928
3929void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3930 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3931 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3932 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3933 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3934}
3935
3936void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3937 VkResult result) {
3938 if (result == VK_SUCCESS) performance_lock_acquired = true;
3939}
3940
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003941void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3942 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003943 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003944 cmd_buffer.second->performance_lock_released = true;
3945 }
3946}
3947
locke-lunargd556cc32019-09-17 01:21:23 -06003948void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003949 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003950 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003951 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003952}
3953
3954void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003955 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003956 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003957 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003958}
3959
Mike Schuchardt2df08912020-12-15 16:28:09 -08003960void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3961 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003962 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003963}
3964
Mike Schuchardt2df08912020-12-15 16:28:09 -08003965void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3966 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3967 const VkAllocationCallbacks *pAllocator,
3968 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3969 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003970 if (VK_SUCCESS != result) return;
3971 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3972}
3973
3974void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003975 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3976 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003977 if (VK_SUCCESS != result) return;
3978 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3979}
3980
3981void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003982 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003983 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003984 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3985 assert(template_state);
3986 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003987 // TODO: Record template push descriptor updates
3988 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003989 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003990 }
3991 }
3992}
3993
3994void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3995 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3996 const void *pData) {
3997 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3998}
3999
4000void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004001 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06004002 const void *pData) {
4003 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
4004}
4005
Mike Schuchardt2df08912020-12-15 16:28:09 -08004006void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
4007 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
4008 VkPipelineLayout layout, uint32_t set,
4009 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004010 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004011
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004012 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07004013 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06004014 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004015 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06004016 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004017 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004018 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06004019 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004020 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06004021 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004022 static_cast<uint32_t>(decoded_template.desc_writes.size()),
4023 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06004024 }
4025}
4026
4027void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
4028 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004029 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06004030 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004031 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004032 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06004033 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06004034 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06004035 }
4036}
4037
4038void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
4039 uint32_t *pPropertyCount,
4040 VkDisplayPlanePropertiesKHR *pProperties,
4041 VkResult result) {
4042 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4043 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4044}
4045
4046void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
4047 uint32_t *pPropertyCount,
4048 VkDisplayPlaneProperties2KHR *pProperties,
4049 VkResult result) {
4050 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
4051 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
4052}
4053
4054void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4055 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
4056 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004057 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004058 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004059 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004060}
4061
4062void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4063 uint32_t query, uint32_t index) {
4064 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004065 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004066 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004067 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004068}
4069
4070void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4071 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02004072 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004073
4074 if (create_info->format != VK_FORMAT_UNDEFINED) {
4075 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07004076 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004077 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4078 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004079 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004080
Jeremy Gebben082a9832021-10-28 13:40:11 -06004081 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004082}
4083
4084void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4085 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4086 const VkAllocationCallbacks *pAllocator,
4087 VkSamplerYcbcrConversion *pYcbcrConversion,
4088 VkResult result) {
4089 if (VK_SUCCESS != result) return;
4090 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4091}
4092
4093void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4094 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4095 const VkAllocationCallbacks *pAllocator,
4096 VkSamplerYcbcrConversion *pYcbcrConversion,
4097 VkResult result) {
4098 if (VK_SUCCESS != result) return;
4099 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4100}
4101
4102void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4103 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004104 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004105}
4106
4107void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4108 VkSamplerYcbcrConversion ycbcrConversion,
4109 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004110 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004111}
4112
Tony-LunarG977448c2019-12-02 14:52:02 -07004113void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4114 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004115 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004116 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004117
4118 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004119 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004120 if (!query_pool_state) return;
4121
4122 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004123 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4124 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004125 auto query_index = firstQuery + i;
4126 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004127 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004128 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004129 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004130 }
4131 }
locke-lunargd556cc32019-09-17 01:21:23 -06004132 }
4133}
4134
Tony-LunarG977448c2019-12-02 14:52:02 -07004135void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4136 uint32_t queryCount) {
4137 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4138}
4139
4140void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4141 uint32_t queryCount) {
4142 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4143}
4144
locke-lunargd556cc32019-09-17 01:21:23 -06004145void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004146 const UPDATE_TEMPLATE_STATE *template_state,
4147 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004148 // Translate the templated update into a normal update for validation...
4149 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4150 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4151 decoded_update.desc_writes.data(), 0, NULL);
4152}
4153
4154// Update the common AllocateDescriptorSetsData
4155void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004156 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004157 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004158 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004159 if (layout) {
4160 ds_data->layout_nodes[i] = layout;
4161 // Count total descriptors required per type
4162 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4163 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004164 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4165 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004166 }
4167 }
4168 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4169 }
4170}
4171
locke-lunargd556cc32019-09-17 01:21:23 -06004172void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4173 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004174 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004175 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004176}
4177
Tony-LunarG745150c2021-07-02 15:07:31 -06004178void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4179 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4180 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004181 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004182 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004183}
4184
locke-lunargd556cc32019-09-17 01:21:23 -06004185void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4186 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4187 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004188 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004189 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004190}
4191
Tony-LunarG745150c2021-07-02 15:07:31 -06004192void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4193 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4194 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4195 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004196 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004197 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004198}
4199
locke-lunargd556cc32019-09-17 01:21:23 -06004200void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4201 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004202 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004203 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004204 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004205 if (!disabled[command_buffer_state]) {
4206 cb_state->AddChild(buffer_state);
4207 }
locke-lunargd556cc32019-09-17 01:21:23 -06004208}
4209
4210void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4211 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004212 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004213 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004214 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004215 if (!disabled[command_buffer_state]) {
4216 cb_state->AddChild(buffer_state);
4217 }
locke-lunargd556cc32019-09-17 01:21:23 -06004218}
4219
4220void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004221 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004222 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004223}
4224
4225void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4226 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004227 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004228 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004229 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004230 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004231 cb_state->AddChild(buffer_state);
4232 }
locke-lunargd556cc32019-09-17 01:21:23 -06004233}
4234
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004235void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4236 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004237 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004238 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4239}
4240
4241void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4242 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004243 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004244 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4245}
4246
Tony-LunarG977448c2019-12-02 14:52:02 -07004247void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4248 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004249 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004250 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004251 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004252 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004253 auto buffer_state = Get<BUFFER_STATE>(buffer);
4254 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004255 cb_state->AddChild(buffer_state);
4256 cb_state->AddChild(count_buffer_state);
4257 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004258}
4259
locke-lunargd556cc32019-09-17 01:21:23 -06004260void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4261 VkDeviceSize offset, VkBuffer countBuffer,
4262 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4263 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004264 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004265 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004266}
4267
4268void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4269 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4270 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004271 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004272 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004273}
4274
4275void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4276 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004277 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004278 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004279 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004280 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004281 auto buffer_state = Get<BUFFER_STATE>(buffer);
4282 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004283 cb_state->AddChild(buffer_state);
4284 cb_state->AddChild(count_buffer_state);
4285 }
locke-lunargd556cc32019-09-17 01:21:23 -06004286}
4287
4288void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4289 VkDeviceSize offset, VkBuffer countBuffer,
4290 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4291 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004292 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004293 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004294}
4295
4296void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4297 VkDeviceSize offset, VkBuffer countBuffer,
4298 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4299 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004300 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004301 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004302}
4303
4304void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4305 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004306 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004307 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004308}
4309
4310void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4311 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004312 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004313 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004314 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004315 if (!disabled[command_buffer_state] && buffer_state) {
4316 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004317 }
4318}
4319
4320void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4321 VkDeviceSize offset, VkBuffer countBuffer,
4322 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4323 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004324 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004325 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004326 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004327 auto buffer_state = Get<BUFFER_STATE>(buffer);
4328 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004329 if (buffer_state) {
4330 cb_state->AddChild(buffer_state);
4331 }
4332 if (count_buffer_state) {
4333 cb_state->AddChild(count_buffer_state);
4334 }
locke-lunargd556cc32019-09-17 01:21:23 -06004335 }
4336}
4337
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004338void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4339 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4340 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4341 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4342 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4343 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4344 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004345 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004346 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004347 cb_state->hasTraceRaysCmd = true;
4348}
4349
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004350void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4351 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4352 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4353 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4354 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4355 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004356 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004357 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004358 cb_state->hasTraceRaysCmd = true;
4359}
4360
4361void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4362 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4363 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4364 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4365 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4366 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004367 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004368 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004369 cb_state->hasTraceRaysCmd = true;
4370}
4371
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004372std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4373 uint32_t unique_shader_id) const {
4374 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4375 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4376 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4377 : std::make_shared<SHADER_MODULE_STATE>();
4378}
4379
4380std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4381 uint32_t unique_shader_id,
4382 VkShaderModule handle) const {
4383 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4384 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4385 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4386 : std::make_shared<SHADER_MODULE_STATE>();
4387}
4388
sfricke-samsungf91881c2022-03-31 01:12:00 -05004389void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer,
4390 VkDeviceAddress indirectDeviceAddress) {
4391 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4392 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECT2KHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
4393 cb_state->hasTraceRaysCmd = true;
4394}
4395
locke-lunargd556cc32019-09-17 01:21:23 -06004396void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4397 const VkAllocationCallbacks *pAllocator,
4398 VkShaderModule *pShaderModule, VkResult result,
4399 void *csm_state_data) {
4400 if (VK_SUCCESS != result) return;
4401 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4402
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004403 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004404}
4405
John Zulauf22b0fbe2019-10-15 06:26:16 -06004406void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4407 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4408 VkResult result) {
4409 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004410 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004411
4412 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4413
4414 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004415 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004416 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004417 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004418
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004419 auto format_features = GetImageFormatFeatures(
4420 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4421 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004422
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004423 auto image_state =
4424 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004425 if (!swapchain_image.fake_base_address) {
4426 auto size = image_state->fragment_encoder->TotalSize();
4427 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004428 }
4429
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004430 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004431 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004432 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004433 }
4434 }
4435
4436 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004437 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4438 }
4439}
sourav parmar35e7a002020-06-09 17:58:44 -07004440
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004441void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4442 const VkCopyAccelerationStructureInfoKHR *pInfo,
4443 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004444 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4445 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004446 if (dst_as_state != nullptr && src_as_state != nullptr) {
4447 dst_as_state->built = true;
4448 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4449 }
4450}
4451
sourav parmar35e7a002020-06-09 17:58:44 -07004452void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4453 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004454 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004455 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004456 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004457 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4458 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004459 if (dst_as_state != nullptr && src_as_state != nullptr) {
4460 dst_as_state->built = true;
4461 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004462 if (!disabled[command_buffer_state]) {
4463 cb_state->AddChild(dst_as_state);
4464 cb_state->AddChild(src_as_state);
4465 }
sourav parmar35e7a002020-06-09 17:58:44 -07004466 }
4467 }
4468}
Piers Daniell39842ee2020-07-10 16:42:33 -06004469
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004470void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4471 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4472 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4473 if (cb_state) {
4474 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4475 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4476 if (!disabled[command_buffer_state]) {
4477 cb_state->AddChild(src_as_state);
4478 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004479 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4480 if (dst_buffer) {
4481 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004482 }
4483 }
4484}
4485
4486void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4487 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4488 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4489 if (cb_state) {
4490 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4491 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004492 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4493 if (buffer_state) {
4494 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004495 }
4496 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4497 cb_state->AddChild(dst_as_state);
4498 }
4499 }
4500}
4501
Piers Daniell39842ee2020-07-10 16:42:33 -06004502void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004503 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004504 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004505}
4506
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004507void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4508 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4509 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4510}
4511
Piers Daniell39842ee2020-07-10 16:42:33 -06004512void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004513 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004514 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004515}
4516
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004517void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4518 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4519 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4520}
4521
Piers Daniell39842ee2020-07-10 16:42:33 -06004522void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4523 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004524 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004525 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004526 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004527}
4528
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004529void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4530 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004531 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004532 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4533 cb_state->primitiveTopology = primitiveTopology;
4534}
4535
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004536void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4537 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004538 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4539 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004540 uint32_t bits = (1u << viewportCount) - 1u;
4541 cb_state->viewportWithCountMask |= bits;
4542 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004543 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004544 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004545
4546 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4547 for (size_t i = 0; i < viewportCount; ++i) {
4548 cb_state->dynamicViewports[i] = pViewports[i];
4549 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004550}
4551
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004552void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4553 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004554 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004555}
4556
4557void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004558 const VkViewport *pViewports) {
4559 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004560}
4561
4562void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4563 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004564 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004565 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004566 uint32_t bits = (1u << scissorCount) - 1u;
4567 cb_state->scissorWithCountMask |= bits;
4568 cb_state->trashedScissorMask &= ~bits;
4569 cb_state->scissorWithCountCount = scissorCount;
4570 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004571}
4572
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004573void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4574 const VkRect2D *pScissors) {
4575 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4576}
4577
4578void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4579 const VkRect2D *pScissors) {
4580 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4581}
4582
4583void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4584 uint32_t bindingCount, const VkBuffer *pBuffers,
4585 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4586 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004587 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004588 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004589
4590 uint32_t end = firstBinding + bindingCount;
4591 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4592 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4593 }
4594
4595 for (uint32_t i = 0; i < bindingCount; ++i) {
4596 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004597 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004598 vertex_buffer_binding.offset = pOffsets[i];
4599 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4600 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4601 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004602 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004603 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004604 }
4605 }
4606}
4607
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004608void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4609 uint32_t bindingCount, const VkBuffer *pBuffers,
4610 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4611 const VkDeviceSize *pStrides) {
4612 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4613 CMD_BINDVERTEXBUFFERS2EXT);
4614}
4615
4616void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4617 uint32_t bindingCount, const VkBuffer *pBuffers,
4618 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4619 const VkDeviceSize *pStrides) {
4620 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4621 CMD_BINDVERTEXBUFFERS2);
4622}
4623
Piers Daniell39842ee2020-07-10 16:42:33 -06004624void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004625 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004626 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004627}
4628
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004629void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4630 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4631 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4632}
4633
Piers Daniell39842ee2020-07-10 16:42:33 -06004634void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004635 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004636 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004637}
4638
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004639void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4640 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4641 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4642}
4643
Piers Daniell39842ee2020-07-10 16:42:33 -06004644void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004645 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004646 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004647}
4648
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004649void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4650 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4651 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4652}
4653
Piers Daniell39842ee2020-07-10 16:42:33 -06004654void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4655 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004656 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004657 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004658}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004659
4660void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4661 VkBool32 depthBoundsTestEnable) {
4662 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4663 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4664}
4665
Piers Daniell39842ee2020-07-10 16:42:33 -06004666void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004667 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004668 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004669}
4670
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004671void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4672 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4673 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4674}
4675
Piers Daniell39842ee2020-07-10 16:42:33 -06004676void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4677 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4678 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004679 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004680 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004681}
locke-lunarg4189aa22020-10-21 00:23:48 -06004682
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004683void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4684 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4685 VkCompareOp compareOp) {
4686 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4687 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4688}
4689
locke-lunarg4189aa22020-10-21 00:23:48 -06004690void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4691 uint32_t discardRectangleCount,
4692 const VkRect2D *pDiscardRectangles) {
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_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004695}
4696
4697void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4698 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004699 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004700 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004701}
4702
4703void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4704 VkCoarseSampleOrderTypeNV sampleOrderType,
4705 uint32_t customSampleOrderCount,
4706 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004707 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004708 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004709}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004710
4711void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004712 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004713 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004714}
4715
4716void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004717 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004718 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004719}
4720
4721void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4722 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004723 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004724 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004725}
4726
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004727void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4728 VkBool32 rasterizerDiscardEnable) {
4729 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4730 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4731}
4732
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004733void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004734 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004735 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004736}
4737
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004738void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4739 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4740 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4741}
4742
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004743void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4744 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004745 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004746 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004747}
Piers Daniell924cd832021-05-18 13:48:47 -06004748
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004749void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4750 VkBool32 primitiveRestartEnable) {
4751 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4752 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4753}
4754
Piers Daniell924cd832021-05-18 13:48:47 -06004755void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4756 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4757 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4758 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004759 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004760 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4761
4762 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4763 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4764 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004765 const auto *dynamic_state = pipeline_state->DynamicState();
4766 if (dynamic_state) {
4767 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4768 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004769 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4770 break;
4771 }
4772 }
4773 }
4774 }
4775 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004776}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004777
ziga-lunarg67b7c392022-03-26 01:45:34 +01004778void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4779 const VkBool32 *pColorWriteEnables) {
4780 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4781 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4782 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4783}
4784
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004785void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004786 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004787 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004788 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004789 // address is used for GPU-AV and ray tracing buffer validation
4790 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004791 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004792 }
4793}
4794
4795void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4796 VkDeviceAddress address) {
4797 RecordGetBufferDeviceAddress(pInfo, address);
4798}
4799
4800void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4801 VkDeviceAddress address) {
4802 RecordGetBufferDeviceAddress(pInfo, address);
4803}
4804
4805void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4806 VkDeviceAddress address) {
4807 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004808}
4809
4810std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4811 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004812 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004813}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004814
4815std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4816 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004817 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004818 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4819}