blob: a026928e396caae88a6cf190f4cbc2f022c012b2 [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
Mark Lobodzinskib4ab6ac2020-04-02 13:12:06 -060042void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) {
43 if (add_obj) {
44 instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type));
45 // Call base class
46 ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj);
47 }
48}
49
John Zulauf2bc1fde2020-04-24 15:09:51 -060050// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
51// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060052static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
53 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060054 const VkImageView *attachments = fb_state.createInfo.pAttachments;
55 uint32_t count = fb_state.createInfo.attachmentCount;
56 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070057 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060058 if (framebuffer_attachments) {
59 attachments = framebuffer_attachments->pAttachments;
60 count = framebuffer_attachments->attachmentCount;
61 }
62 }
63 return std::make_pair(count, attachments);
64}
65
John Zulauf64ffe552021-02-06 10:25:07 -070066template <typename ImageViewPointer, typename Get>
67std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
68 const Get &get_fn) {
69 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060070
71 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
72 const auto attachment_count = count_attachment.first;
73 const auto *attachments = count_attachment.second;
74 views.resize(attachment_count, nullptr);
75 for (uint32_t i = 0; i < attachment_count; i++) {
76 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070077 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060078 }
79 }
80 return views;
81}
82
Jeremy Gebben9f537102021-10-05 16:37:12 -060083std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070084 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060085 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070086 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
87}
88
locke-lunargd556cc32019-09-17 01:21:23 -060089#ifdef VK_USE_PLATFORM_ANDROID_KHR
90// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
91// This could also move into a seperate core_validation_android.cpp file... ?
92
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020094VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060095 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070096 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060097 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070098 // VUID 01894 will catch if not found in map
99 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
100 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600101 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700102 }
locke-lunargd556cc32019-09-17 01:21:23 -0600103 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600104 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -0600105}
106
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700107void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
108 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
109 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200110 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
111 if (ahb_format_props2) {
112 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
113 } else {
114 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
115 if (ahb_format_props) {
116 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
117 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
118 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700119 }
120}
121
locke-lunargd556cc32019-09-17 01:21:23 -0600122#else
123
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600124template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200125VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600126 return 0;
127}
locke-lunargd556cc32019-09-17 01:21:23 -0600128
129#endif // VK_USE_PLATFORM_ANDROID_KHR
130
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
132 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200133 VkFormatFeatureFlags2KHR format_features = 0;
134
Petr Kraus44f1c482020-04-25 20:09:25 +0200135 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
136 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200137 if (has_format_feature2) {
138 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200139 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200140 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
141
142 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
143
144 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
145 VkImageDrmFormatModifierPropertiesEXT drm_format_props = {
146 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
147 nullptr,
148 };
149
150 // Find the image modifier
151 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
152
153 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
154 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
155 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
156
157 // Second query to have all the modifiers filled
158 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
159
160 // Look for the image modifier in the list
161 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
162 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
163 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
164 break;
165 }
166 }
167 } else {
168 format_features =
169 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
170 }
171 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600172 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
173 nullptr};
174 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200175
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600176 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
177 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
178 nullptr};
179 format_properties_2.pNext = (void *)&drm_properties_list;
180 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
181 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
182 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
183 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
184 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200185
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600186 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
187 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
188 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
189 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200190 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200191 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600192 } else {
193 VkFormatProperties format_properties;
194 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
195 format_features =
196 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200197 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600198 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200199}
200
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700201std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
202 VkFormatFeatureFlags2KHR features) {
203 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, features);
204}
205
206std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
207 VkSwapchainKHR swapchain, uint32_t swapchain_index,
208 VkFormatFeatureFlags2KHR features) {
209 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, swapchain, swapchain_index, features);
210}
211
locke-lunargd556cc32019-09-17 01:21:23 -0600212void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
213 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
214 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200215 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700216 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600217 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600218 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600219 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200220 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
221 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
222 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600223 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700224 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600225}
226
227void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600228 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600229}
230
231void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
232 VkImageLayout imageLayout, const VkClearColorValue *pColor,
233 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600234 if (disabled[command_buffer_state]) return;
235
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700236 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600237 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600238 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600239 }
240}
241
242void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
243 VkImageLayout imageLayout,
244 const VkClearDepthStencilValue *pDepthStencil,
245 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600246 if (disabled[command_buffer_state]) return;
247
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700248 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600249 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600250 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600251 }
252}
253
254void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
255 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
256 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600257 if (disabled[command_buffer_state]) return;
258
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700259 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600260 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600261}
262
Jeff Leger178b1e52020-10-05 12:22:23 -0400263void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
264 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600265 if (disabled[command_buffer_state]) return;
266
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700267 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600268 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
269 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400270}
271
Tony-LunarGb61514a2021-11-02 12:36:51 -0600272void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
273 if (disabled[command_buffer_state]) return;
274
275 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
276 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
277 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
278}
279
locke-lunargd556cc32019-09-17 01:21:23 -0600280void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
281 VkImageLayout srcImageLayout, VkImage dstImage,
282 VkImageLayout dstImageLayout, uint32_t regionCount,
283 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600284 if (disabled[command_buffer_state]) return;
285
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700286 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600287 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600288}
289
Jeff Leger178b1e52020-10-05 12:22:23 -0400290void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
291 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600292 if (disabled[command_buffer_state]) return;
293
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700294 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600295 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
296 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400297}
298
Tony-LunarG562fc102021-11-12 13:58:35 -0700299void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
300 const VkResolveImageInfo2 *pResolveImageInfo) {
301 if (disabled[command_buffer_state]) return;
302
303 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
304 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
305 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
306}
307
locke-lunargd556cc32019-09-17 01:21:23 -0600308void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
309 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
310 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600311 if (disabled[command_buffer_state]) return;
312
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700313 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600314 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600315}
316
Jeff Leger178b1e52020-10-05 12:22:23 -0400317void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
318 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600319 if (disabled[command_buffer_state]) return;
320
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700321 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600322 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
323 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400324}
325
Tony-LunarG542ae912021-11-04 16:06:44 -0600326void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
327 if (disabled[command_buffer_state]) return;
328
329 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
330 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
331 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
332}
333
locke-lunargd556cc32019-09-17 01:21:23 -0600334void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
335 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
336 VkResult result) {
337 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600338
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600339 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600340
James Rumble2f6e7bb2021-07-13 15:21:20 +0100341 if (pCreateInfo) {
342 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700343 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700344 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100345 // address is used for GPU-AV and ray tracing buffer validation
346 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700347 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100348 }
349 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600350 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600351}
352
353void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
354 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
355 VkResult result) {
356 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600357
Jeremy Gebben9f537102021-10-05 16:37:12 -0600358 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600359
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200360 VkFormatFeatureFlags2KHR buffer_features;
361 if (has_format_feature2) {
362 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
363 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
364 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
365 buffer_features = fmt_props_3.bufferFeatures;
366 } else {
367 VkFormatProperties format_properties;
368 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
369 buffer_features = format_properties.bufferFeatures;
370 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600371
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200372 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600373}
374
375void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
376 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
377 VkResult result) {
378 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600379 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700380
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200381 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600382 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700383 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600384 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700385 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200386 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
387 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
388 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700389 }
390
locke-lunarg9939d4b2020-10-26 20:11:08 -0600391 // 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 -0600392 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600393 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700394 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600395 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700396 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600397 image_format_info.type = image_state->createInfo.imageType;
398 image_format_info.format = image_state->createInfo.format;
399 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600400 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
401 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600402 image_format_info.flags = image_state->createInfo.flags;
403
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600404 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600405
406 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
407 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600408
Jeremy Gebben082a9832021-10-28 13:40:11 -0600409 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600410}
411
412void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
413 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600414 if (disabled[command_buffer_state]) return;
415
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700416 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600417 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600418}
419
Jeff Leger178b1e52020-10-05 12:22:23 -0400420void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600421 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600422 if (disabled[command_buffer_state]) return;
423
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700424 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600425 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
426 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400427}
428
Tony-LunarGef035472021-11-02 10:23:33 -0600429void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
430 if (disabled[command_buffer_state]) return;
431
432 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
433 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
434 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
435}
436
locke-lunargd556cc32019-09-17 01:21:23 -0600437void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
438 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600439 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600440}
441
442void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700443 auto buffer_state = Get<BUFFER_STATE>(buffer);
444 if (buffer_state) {
445 WriteLockGuard guard(buffer_address_lock_);
446 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
447 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600448 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600449}
450
451void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
452 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600453 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600454}
455
456void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
457 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600458 if (disabled[command_buffer_state]) return;
459
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700460 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600461 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600462}
463
464void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
465 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
466 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600467 if (disabled[command_buffer_state]) return;
468
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700469 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600470
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600471 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600472}
473
Jeff Leger178b1e52020-10-05 12:22:23 -0400474void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
475 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600476 if (disabled[command_buffer_state]) return;
477
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700478 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600479 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
480 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400481}
482
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700483void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
484 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
485 if (disabled[command_buffer_state]) return;
486
487 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
488 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
489 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
490}
491
locke-lunargd556cc32019-09-17 01:21:23 -0600492void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
493 VkImageLayout dstImageLayout, uint32_t regionCount,
494 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600495 if (disabled[command_buffer_state]) return;
496
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700497 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600498 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600499}
500
Jeff Leger178b1e52020-10-05 12:22:23 -0400501void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
502 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600503 if (disabled[command_buffer_state]) return;
504
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700505 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600506 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
507 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400508}
509
Tony Barbour845d29b2021-11-09 11:43:14 -0700510void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
511 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
512 if (disabled[command_buffer_state]) return;
513
514 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
515 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
516 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
517}
518
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700519// Gets union of all features defined by Potential Format Features
520// 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 +0200521VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
522 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700523
524 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200525 if (has_format_feature2) {
526 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200527 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
528 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200529 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100530
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200531 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100532
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200533 format_features |= fmt_props_3.linearTilingFeatures;
534 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100535
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200536 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
537 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
538 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
539 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
540 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100541
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200542 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
543 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
544 }
545 }
546 } else {
547 VkFormatProperties format_properties;
548 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
549 format_features |= format_properties.linearTilingFeatures;
550 format_features |= format_properties.optimalTilingFeatures;
551
552 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
553 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
554 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
555
556 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
557
558 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
559 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
560 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
561 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
562
563 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
564 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
565 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700566 }
567 }
568 }
569
570 return format_features;
571}
572
locke-lunargd556cc32019-09-17 01:21:23 -0600573void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
574 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
575 VkResult result) {
576 if (VK_SUCCESS != result) return;
577
Locke Linf3873542021-04-26 11:25:10 -0600578 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
579 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
580 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
581
locke-lunargd556cc32019-09-17 01:21:23 -0600582 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
583 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700584 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600585 if (features2) {
586 enabled_features_found = &(features2->features);
587 }
588 }
589
locke-lunargd556cc32019-09-17 01:21:23 -0600590 if (nullptr == enabled_features_found) {
591 state_tracker->enabled_features.core = {};
592 } else {
593 state_tracker->enabled_features.core = *enabled_features_found;
594 }
595
locke-lunargd556cc32019-09-17 01:21:23 -0600596 // Save local link to this device's physical device state
Jeremy Gebben9f537102021-10-05 16:37:12 -0600597 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
locke-lunargd556cc32019-09-17 01:21:23 -0600598
Tony-LunarG273f32f2021-09-28 08:56:30 -0600599 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
600 if (vulkan_13_features) {
601 state_tracker->enabled_features.core13 = *vulkan_13_features;
602 } else {
603 state_tracker->enabled_features.core13 = {};
604 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
605 if (image_robustness_features) {
606 state_tracker->enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
607 }
608
609 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
610 if (inline_uniform_block_features) {
611 state_tracker->enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
612 state_tracker->enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
613 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
614 }
615
616 const auto *pipeline_creation_cache_control_features =
617 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
618 if (pipeline_creation_cache_control_features) {
619 state_tracker->enabled_features.core13.pipelineCreationCacheControl =
620 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
621 }
622
623 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
624 if (private_data_features) {
625 state_tracker->enabled_features.core13.privateData = private_data_features->privateData;
626 }
627
628 const auto *demote_to_helper_invocation_features =
629 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
630 if (demote_to_helper_invocation_features) {
631 state_tracker->enabled_features.core13.shaderDemoteToHelperInvocation =
632 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
633 }
634
635 const auto *terminate_invocation_features =
636 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
637 if (terminate_invocation_features) {
638 state_tracker->enabled_features.core13.shaderTerminateInvocation =
639 terminate_invocation_features->shaderTerminateInvocation;
640 }
641
642 const auto *subgroup_size_control_features =
643 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
644 if (subgroup_size_control_features) {
645 state_tracker->enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
646 state_tracker->enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
647 }
648
649 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
650 if (synchronization2_features) {
651 state_tracker->enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
652 }
653
654 const auto *texture_compression_astchdr_features =
655 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
656 if (texture_compression_astchdr_features) {
657 state_tracker->enabled_features.core13.textureCompressionASTC_HDR =
658 texture_compression_astchdr_features->textureCompressionASTC_HDR;
659 }
660
661 const auto *initialize_workgroup_memory_features =
662 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
663 if (initialize_workgroup_memory_features) {
664 state_tracker->enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
665 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
666 }
667
668 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
669 if (dynamic_rendering_features) {
670 state_tracker->enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
671 }
672
673 const auto *shader_integer_dot_product_features =
674 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
675 if (shader_integer_dot_product_features) {
676 state_tracker->enabled_features.core13.shaderIntegerDotProduct =
677 shader_integer_dot_product_features->shaderIntegerDotProduct;
678 }
679
680 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
681 if (maintenance4_features) {
682 state_tracker->enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
683 }
684 }
685
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700686 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700687 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700688 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700689 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700690 // Set Extension Feature Aliases to false as there is no struct to check
691 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
692 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
693 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
694 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
695 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
696 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800697 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700698
699 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700700
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700701 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700702 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700703 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
704 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
705 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
706 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700707 }
708
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700709 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700710 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700711 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
712 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700713 }
714
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700715 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700716 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700717 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
718 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
719 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
720 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
721 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
722 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
723 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
724 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
725 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
726 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
727 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
728 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
729 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
730 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
731 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
732 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
733 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
734 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
735 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
736 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
737 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
738 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
739 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
740 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
741 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
742 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
743 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
744 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
745 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
746 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
747 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
748 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
749 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
750 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
751 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
752 descriptor_indexing_features->descriptorBindingPartiallyBound;
753 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
754 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
755 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700756 }
757
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700758 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700760 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700761 }
762
763 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700764 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700766 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700767 }
768
769 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700770 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700771 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700772 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
773 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700774 }
775
776 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700777 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700779 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
780 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700781 }
782
783 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700784 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700785 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700786 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
787 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700788 }
789
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700790 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700792 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700793 }
794
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700795 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700796 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700797 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700798 }
799
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700800 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700801 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700802 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
803 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
804 buffer_device_address->bufferDeviceAddressCaptureReplay;
805 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
806 buffer_device_address->bufferDeviceAddressMultiDevice;
807 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800808
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700809 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800810 if (atomic_int64_features) {
811 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
812 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
813 }
814
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700815 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800816 if (memory_model_features) {
817 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
818 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
819 memory_model_features->vulkanMemoryModelDeviceScope;
820 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
821 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
822 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700823 }
824
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700825 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700826 if (vulkan_11_features) {
827 state_tracker->enabled_features.core11 = *vulkan_11_features;
828 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700829 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700830
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700831 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700832 if (sixteen_bit_storage_features) {
833 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
834 sixteen_bit_storage_features->storageBuffer16BitAccess;
835 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
836 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
837 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
838 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
839 }
840
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700841 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700842 if (multiview_features) {
843 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
844 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
845 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
846 }
847
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700848 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 if (variable_pointers_features) {
850 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
851 variable_pointers_features->variablePointersStorageBuffer;
852 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
853 }
854
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700855 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700856 if (protected_memory_features) {
857 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
858 }
859
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700860 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700861 if (ycbcr_conversion_features) {
862 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
863 }
864
865 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700866 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700867 if (shader_draw_parameters_features) {
868 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700869 }
870 }
871
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700872 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600873 if (device_group_ci) {
874 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
875 state_tracker->device_group_create_info = *device_group_ci;
876 } else {
877 state_tracker->physical_device_count = 1;
878 }
locke-lunargd556cc32019-09-17 01:21:23 -0600879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 // Features from other extensions passesd in create info
881 {
882 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
883 if (exclusive_scissor_features) {
884 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
885 }
locke-lunargd556cc32019-09-17 01:21:23 -0600886
sfricke-samsung828e59d2021-08-22 23:20:49 -0700887 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
888 if (shading_rate_image_features) {
889 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
890 }
locke-lunargd556cc32019-09-17 01:21:23 -0600891
sfricke-samsung828e59d2021-08-22 23:20:49 -0700892 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
893 if (mesh_shader_features) {
894 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
895 }
locke-lunargd556cc32019-09-17 01:21:23 -0600896
sfricke-samsung828e59d2021-08-22 23:20:49 -0700897 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
898 if (transform_feedback_features) {
899 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
900 }
locke-lunargd556cc32019-09-17 01:21:23 -0600901
sfricke-samsung828e59d2021-08-22 23:20:49 -0700902 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
903 if (vtx_attrib_div_features) {
904 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
905 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700906
sfricke-samsung828e59d2021-08-22 23:20:49 -0700907 const auto *buffer_device_address_ext_features =
908 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
909 if (buffer_device_address_ext_features) {
910 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
911 }
locke-lunargd556cc32019-09-17 01:21:23 -0600912
sfricke-samsung828e59d2021-08-22 23:20:49 -0700913 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
914 if (cooperative_matrix_features) {
915 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *compute_shader_derivatives_features =
919 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
920 if (compute_shader_derivatives_features) {
921 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
922 }
locke-lunargd556cc32019-09-17 01:21:23 -0600923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *fragment_shader_barycentric_features =
925 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
926 if (fragment_shader_barycentric_features) {
927 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
928 }
locke-lunargd556cc32019-09-17 01:21:23 -0600929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *shader_image_footprint_features =
931 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
932 if (shader_image_footprint_features) {
933 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
934 }
locke-lunargd556cc32019-09-17 01:21:23 -0600935
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 const auto *fragment_shader_interlock_features =
937 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
938 if (fragment_shader_interlock_features) {
939 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *texel_buffer_alignment_features =
943 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
944 if (texel_buffer_alignment_features) {
945 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
946 }
locke-lunargd556cc32019-09-17 01:21:23 -0600947
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 const auto *pipeline_exe_props_features =
949 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
950 if (pipeline_exe_props_features) {
951 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
952 }
locke-lunargd556cc32019-09-17 01:21:23 -0600953
sfricke-samsung828e59d2021-08-22 23:20:49 -0700954 const auto *dedicated_allocation_image_aliasing_features =
955 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
956 if (dedicated_allocation_image_aliasing_features) {
957 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
958 *dedicated_allocation_image_aliasing_features;
959 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500960
sfricke-samsung828e59d2021-08-22 23:20:49 -0700961 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
962 if (performance_query_features) {
963 state_tracker->enabled_features.performance_query_features = *performance_query_features;
964 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100965
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
967 if (device_coherent_memory_features) {
968 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
969 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000970
sfricke-samsung828e59d2021-08-22 23:20:49 -0700971 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
972 if (ycbcr_image_array_features) {
973 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
974 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800975
sfricke-samsung828e59d2021-08-22 23:20:49 -0700976 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
977 if (ray_query_features) {
978 state_tracker->enabled_features.ray_query_features = *ray_query_features;
979 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700980
sfricke-samsung828e59d2021-08-22 23:20:49 -0700981 const auto *ray_tracing_pipeline_features =
982 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
983 if (ray_tracing_pipeline_features) {
984 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
985 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700986
sfricke-samsung828e59d2021-08-22 23:20:49 -0700987 const auto *ray_tracing_acceleration_structure_features =
988 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
989 if (ray_tracing_acceleration_structure_features) {
990 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
991 *ray_tracing_acceleration_structure_features;
992 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500993
sfricke-samsung828e59d2021-08-22 23:20:49 -0700994 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
995 if (robustness2_features) {
996 state_tracker->enabled_features.robustness2_features = *robustness2_features;
997 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500998
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 const auto *fragment_density_map_features =
1000 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1001 if (fragment_density_map_features) {
1002 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
1003 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001004
sfricke-samsung828e59d2021-08-22 23:20:49 -07001005 const auto *fragment_density_map_features2 =
1006 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1007 if (fragment_density_map_features2) {
1008 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
1009 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001010
Agarwal, Arpit78509112022-02-17 15:29:05 -07001011 const auto *fragment_density_map_offset_features =
1012 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1013 if (fragment_density_map_offset_features) {
1014 state_tracker->enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
1015 }
1016
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1018 if (astc_decode_features) {
1019 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
1020 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001021
sfricke-samsung828e59d2021-08-22 23:20:49 -07001022 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1023 if (custom_border_color_features) {
1024 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
1025 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001026
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 const auto *fragment_shading_rate_features =
1028 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1029 if (fragment_shading_rate_features) {
1030 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
1031 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001032
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 const auto *extended_dynamic_state_features =
1034 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1035 if (extended_dynamic_state_features) {
1036 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
1037 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001038
sfricke-samsung828e59d2021-08-22 23:20:49 -07001039 const auto *extended_dynamic_state2_features =
1040 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1041 if (extended_dynamic_state2_features) {
1042 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
1043 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001044
sfricke-samsung828e59d2021-08-22 23:20:49 -07001045 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1046 if (multiview_features) {
1047 state_tracker->enabled_features.multiview_features = *multiview_features;
1048 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001049
sfricke-samsung828e59d2021-08-22 23:20:49 -07001050 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1051 if (portability_features) {
1052 state_tracker->enabled_features.portability_subset_features = *portability_features;
1053 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001054
sfricke-samsung828e59d2021-08-22 23:20:49 -07001055 const auto *shader_integer_functions2_features =
1056 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1057 if (shader_integer_functions2_features) {
1058 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1059 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001060
sfricke-samsung828e59d2021-08-22 23:20:49 -07001061 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1062 if (shader_sm_builtins_features) {
1063 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
1064 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001065
sfricke-samsung828e59d2021-08-22 23:20:49 -07001066 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1067 if (shader_atomic_float_features) {
1068 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
1069 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001070
sfricke-samsung828e59d2021-08-22 23:20:49 -07001071 const auto *shader_image_atomic_int64_features =
1072 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1073 if (shader_image_atomic_int64_features) {
1074 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1075 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001076
sfricke-samsung828e59d2021-08-22 23:20:49 -07001077 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1078 if (shader_clock_features) {
1079 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1080 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001081
sfricke-samsung828e59d2021-08-22 23:20:49 -07001082 const auto *conditional_rendering_features =
1083 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1084 if (conditional_rendering_features) {
1085 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1086 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001087
sfricke-samsung828e59d2021-08-22 23:20:49 -07001088 const auto *workgroup_memory_explicit_layout_features =
1089 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1090 if (workgroup_memory_explicit_layout_features) {
1091 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1092 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001093
sfricke-samsung828e59d2021-08-22 23:20:49 -07001094 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1095 if (provoking_vertex_features) {
1096 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1097 }
Locke Linf3873542021-04-26 11:25:10 -06001098
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 const auto *vertex_input_dynamic_state_features =
1100 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1101 if (vertex_input_dynamic_state_features) {
1102 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1103 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001104
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 const auto *inherited_viewport_scissor_features =
1106 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1107 if (inherited_viewport_scissor_features) {
1108 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1109 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001110
sfricke-samsung828e59d2021-08-22 23:20:49 -07001111 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1112 if (multi_draw_features) {
1113 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1114 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001115
sfricke-samsung828e59d2021-08-22 23:20:49 -07001116 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1117 if (color_write_features) {
1118 state_tracker->enabled_features.color_write_features = *color_write_features;
1119 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001120
sfricke-samsung828e59d2021-08-22 23:20:49 -07001121 const auto *shader_atomic_float2_features =
1122 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1123 if (shader_atomic_float2_features) {
1124 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1125 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001126
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1128 if (present_id_features) {
1129 state_tracker->enabled_features.present_id_features = *present_id_features;
1130 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001131
sfricke-samsung828e59d2021-08-22 23:20:49 -07001132 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1133 if (present_wait_features) {
1134 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1135 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001136
1137 const auto *ray_tracing_motion_blur_features =
1138 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1139 if (ray_tracing_motion_blur_features) {
1140 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1141 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001142
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001143 const auto *primitive_topology_list_restart_features =
1144 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1145 if (primitive_topology_list_restart_features) {
1146 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1147 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001148
ziga-lunarge1988962021-09-16 13:32:34 +02001149 const auto *zero_initialize_work_group_memory_features =
1150 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1151 if (zero_initialize_work_group_memory_features) {
1152 state_tracker->enabled_features.zero_initialize_work_group_memory_features =
1153 *zero_initialize_work_group_memory_features;
1154 }
1155
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001156 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1157 if (rgba10x6_formats_features) {
1158 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
1159 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001160
Tony-LunarG69604c42021-11-22 16:00:12 -07001161 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1162 if (image_view_min_lod_features) {
1163 state_tracker->enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
1164 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001165 }
1166
locke-lunargd556cc32019-09-17 01:21:23 -06001167 // Store physical device properties and physical device mem limits into CoreChecks structs
1168 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1169 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1170
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001171 {
1172 uint32_t n_props = 0;
1173 std::vector<VkExtensionProperties> props;
1174 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, NULL);
1175 props.resize(n_props);
Tony-LunarG8c380b92022-01-12 13:44:04 -07001176 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001177
1178 for (const auto &ext_prop : props) {
1179 state_tracker->phys_dev_extensions.insert(ext_prop.extensionName);
1180 }
1181
1182 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1183 // a path to grab that information from the physical device. This
1184 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1185 // Vulkan 1.1 (which made this core).
1186 state_tracker->has_format_feature2 =
1187 (state_tracker->api_version >= VK_API_VERSION_1_1 ||
1188 IsExtEnabled(state_tracker->instance_extensions.vk_khr_get_physical_device_properties2)) &&
1189 state_tracker->phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) !=
1190 state_tracker->phys_dev_extensions.end();
1191 }
1192
locke-lunargd556cc32019-09-17 01:21:23 -06001193 const auto &dev_ext = state_tracker->device_extensions;
1194 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1195
Tony-LunarG273f32f2021-09-28 08:56:30 -06001196 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1197 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
sfricke-samsung45996a42021-09-16 13:45:27 -07001198 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
1199 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001200 if (dev_ext.vk_feature_version_1_3)
1201 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_3, &state_tracker->phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001202 } else {
1203 // VkPhysicalDeviceVulkan11Properties
1204 //
1205 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1206
1207 if (dev_ext.vk_khr_multiview) {
1208 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1209 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1210 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1211 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1212 }
1213
1214 if (dev_ext.vk_khr_maintenance3) {
1215 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1216 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1217 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1218 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1219 }
1220
1221 // Some 1.1 properties were added to core without previous extensions
1222 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1223 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1224 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1225 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1226 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1227
1228 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1229 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1230 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1231 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1232
1233 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1234 }
1235
1236 // VkPhysicalDeviceVulkan12Properties
1237 //
1238 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1239
1240 if (dev_ext.vk_ext_descriptor_indexing) {
1241 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1242 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1243 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1244 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1245 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1246 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1247 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1248 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1249 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1250 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1251 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1252 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1253 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1254 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1255 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1256 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1257 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1258 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1259 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1260 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1261 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1262 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1263 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1264 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1265 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1266 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1267 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1268 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1269 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1270 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1271 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1272 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1273 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1274 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1275 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1276 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1277 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1278 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1279 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1280 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1281 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1282 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1283 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1284 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1285 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1286 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1287 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1288 }
1289
1290 if (dev_ext.vk_khr_depth_stencil_resolve) {
1291 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1292 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1293 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1294 depth_stencil_resolve_props.supportedDepthResolveModes;
1295 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1296 depth_stencil_resolve_props.supportedStencilResolveModes;
1297 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1298 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1299 }
1300
1301 if (dev_ext.vk_khr_timeline_semaphore) {
1302 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1303 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1304 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1305 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1306 }
1307
1308 if (dev_ext.vk_ext_sampler_filter_minmax) {
1309 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1310 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1311 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1312 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1313 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1314 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1315 }
1316
1317 if (dev_ext.vk_khr_shader_float_controls) {
1318 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1319 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1320 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1321 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1322 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1323 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1324 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1325 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1326 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1327 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1328 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1329 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1330 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1331 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1332 float_controls_props.shaderDenormFlushToZeroFloat16;
1333 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1334 float_controls_props.shaderDenormFlushToZeroFloat32;
1335 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1336 float_controls_props.shaderDenormFlushToZeroFloat64;
1337 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1338 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1339 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1340 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1341 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1342 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1343 }
locke-lunargd556cc32019-09-17 01:21:23 -06001344 }
1345
sfricke-samsung828e59d2021-08-22 23:20:49 -07001346 // Extensions with properties to extract to DeviceExtensionProperties
1347 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001348 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1349 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1350 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1351 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001352 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001353 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001354 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1355 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001356 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1357 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001358 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Agarwal, Arpit78509112022-02-17 15:29:05 -07001359 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_qcom_fragment_density_map_offset,
1360 &phys_dev_props->fragment_density_map_offset_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001361 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001362 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001363 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001364 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001365 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001366 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001367 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001368 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001369 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001370 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001371 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001372 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001373
sfricke-samsung45996a42021-09-16 13:45:27 -07001374 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001375 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001376 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1377 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001378 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1379 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1380
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001381 uint32_t num_cooperative_matrix_properties = 0;
1382 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1383 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001384 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001385
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001386 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001387 state_tracker->cooperative_matrix_properties.data());
1388 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001389
locke-lunargd556cc32019-09-17 01:21:23 -06001390 // Store queue family data
1391 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1392 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001393 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001394 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1395 state_tracker->device_queue_info_list.push_back(
1396 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001397 }
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001398 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1399 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1400 VkQueue queue = VK_NULL_HANDLE;
1401 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1402 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1403 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1404 get_info.flags = queue_info.flags;
1405 get_info.queueFamilyIndex = queue_info.queue_family_index;
1406 get_info.queueIndex = i;
1407 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1408 } else {
1409 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1410 }
1411 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001412 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001413 }
locke-lunargd556cc32019-09-17 01:21:23 -06001414 }
1415 }
1416}
1417
1418void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1419 if (!device) return;
1420
Jeremy Gebbend177d922021-10-28 13:42:10 -06001421 command_pool_map_.clear();
1422 assert(command_buffer_map_.empty());
1423 pipeline_map_.clear();
1424 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001425
1426 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001427 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001428 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001429 assert(descriptor_set_map_.empty());
1430 desc_template_map_.clear();
1431 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001432 // Because swapchains are associated with Surfaces, which are at instance level,
1433 // they need to be explicitly destroyed here to avoid continued references to
1434 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001435 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001436 entry.second->Destroy();
1437 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001438 swapchain_map_.clear();
1439 image_view_map_.clear();
1440 image_map_.clear();
1441 buffer_view_map_.clear();
1442 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001443 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001444 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001445}
1446
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001447void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1448 VkFence fence, VkResult result) {
1449 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001450 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001451
Jeremy Gebben57642982021-09-14 14:14:55 -06001452 uint64_t early_retire_seq = 0;
1453
1454 if (submitCount == 0) {
1455 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001456 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001457 early_retire_seq = queue_state->Submit(std::move(submission));
1458 }
locke-lunargd556cc32019-09-17 01:21:23 -06001459
1460 // Now process each individual submit
1461 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001462 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001463 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001464 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001465 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001466 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001467 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1468 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1469 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1470 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001471 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001472 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001473
locke-lunargd556cc32019-09-17 01:21:23 -06001474 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001475 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001476 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1477 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1478 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1479 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001480 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001481 }
1482
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001483 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001484 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001485
locke-lunargd556cc32019-09-17 01:21:23 -06001486 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001487 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001488 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001489 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001490 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001491 }
1492 auto submit_seq = queue_state->Submit(std::move(submission));
1493 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001494 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001495
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001496 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001497 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001498 }
1499}
1500
Tony-LunarG26fe2842021-11-16 14:07:59 -07001501void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1502 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001503 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001504 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001505 uint64_t early_retire_seq = 0;
1506 if (submitCount == 0) {
1507 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001508 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001509 early_retire_seq = queue_state->Submit(std::move(submission));
1510 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001511
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001512 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1513 CB_SUBMISSION submission;
1514 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001515 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1516 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001517 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001518 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001519 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1520 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001521 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001522 }
1523 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1524 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1525
1526 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001527 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001528 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001529 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001530 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001531 }
1532 auto submit_seq = queue_state->Submit(std::move(submission));
1533 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001534 }
locke-lunargd556cc32019-09-17 01:21:23 -06001535 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001536 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001537 }
1538}
1539
Tony-LunarG26fe2842021-11-16 14:07:59 -07001540void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1541 VkFence fence, VkResult result) {
1542 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1543}
1544
1545void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1546 VkFence fence, VkResult result) {
1547 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1548}
1549
locke-lunargd556cc32019-09-17 01:21:23 -06001550void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1551 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1552 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001553 if (VK_SUCCESS != result) {
1554 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001555 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001556 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1557 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1558 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1559
1560 layer_data::optional<DedicatedBinding> dedicated_binding;
1561
1562 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1563 if (dedicated) {
1564 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001565 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001566 assert(buffer_state);
1567 if (!buffer_state) {
1568 return;
1569 }
1570 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1571 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001572 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001573 assert(image_state);
1574 if (!image_state) {
1575 return;
1576 }
1577 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1578 }
1579 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001580 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1581 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001582 return;
1583}
1584
1585void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001586 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001587 if (mem_info) {
1588 fake_memory.Free(mem_info->fake_base_address);
1589 }
1590 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001591}
1592
1593void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1594 VkFence fence, VkResult result) {
1595 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001596 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001597
Jeremy Gebben57642982021-09-14 14:14:55 -06001598 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001599
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001600 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1601 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001602 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001603 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1604 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1605 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001606 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001607 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001608 if (buffer_state && mem_state) {
1609 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1610 }
locke-lunargd556cc32019-09-17 01:21:23 -06001611 }
1612 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001613 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1614 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1615 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001616 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001617 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001618 if (image_state && mem_state) {
1619 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1620 }
locke-lunargd556cc32019-09-17 01:21:23 -06001621 }
1622 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001623 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1624 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1625 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001626 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1627 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001628 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001629 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001630 if (image_state && mem_state) {
1631 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1632 }
locke-lunargd556cc32019-09-17 01:21:23 -06001633 }
1634 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001635 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001636 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001637 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001639 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001640 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001641 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001642 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001643 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001644 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001645 auto submit_seq = queue_state->Submit(std::move(submission));
1646 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001647 }
1648
1649 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001650 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001651 }
1652}
1653
1654void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1655 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1656 VkResult result) {
1657 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001658 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001659}
1660
Mike Schuchardt2df08912020-12-15 16:28:09 -08001661void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1662 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001663 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1664 if (semaphore_state) {
1665 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001666 }
1667}
1668
Mike Schuchardt2df08912020-12-15 16:28:09 -08001669void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001670 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001671 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001672 if (semaphore_state) {
1673 semaphore_state->RetireTimeline(pSignalInfo->value);
1674 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001675}
1676
locke-lunargd556cc32019-09-17 01:21:23 -06001677void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001678 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001679 if (mem_info) {
1680 mem_info->mapped_range.offset = offset;
1681 mem_info->mapped_range.size = size;
1682 mem_info->p_driver_data = *ppData;
1683 }
1684}
1685
locke-lunargd556cc32019-09-17 01:21:23 -06001686void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1687 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1688 if (VK_SUCCESS != result) return;
1689
1690 // When we know that all fences are complete we can clean/remove their CBs
1691 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1692 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001693 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001694 if (fence_state) {
1695 fence_state->Retire();
1696 }
locke-lunargd556cc32019-09-17 01:21:23 -06001697 }
1698 }
1699 // NOTE : Alternate case not handled here is when some fences have completed. In
1700 // this case for app to guarantee which fences completed it will have to call
1701 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1702}
1703
John Zulauff89de662020-04-13 18:57:34 -06001704void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1705 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001706 if (VK_SUCCESS != result) return;
1707
Jeremy Gebben15332642021-12-15 19:33:15 -07001708 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1709 // the application calls vkGetSemaphoreCounterValue() on each of them.
1710 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1711 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1712 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1713 if (semaphore_state) {
1714 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1715 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001716 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001717 }
1718}
1719
John Zulauff89de662020-04-13 18:57:34 -06001720void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1721 VkResult result) {
1722 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1723}
1724
1725void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1726 uint64_t timeout, VkResult result) {
1727 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1728}
1729
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001730void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1731 VkResult result) {
1732 if (VK_SUCCESS != result) return;
1733
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001734 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001735 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001736 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001737 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001738}
1739
1740void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1741 VkResult result) {
1742 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1743}
1744void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1745 VkResult result) {
1746 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1747}
1748
locke-lunargd556cc32019-09-17 01:21:23 -06001749void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1750 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001751 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001752 if (fence_state) {
1753 fence_state->Retire();
1754 }
locke-lunargd556cc32019-09-17 01:21:23 -06001755}
1756
Yilong Lice03a312022-01-02 02:08:35 -08001757void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1758 if (Get<QUEUE_STATE>(queue) == nullptr) {
1759 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1760 }
1761}
1762
1763void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1764 VkQueue *pQueue) {
1765 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1766}
1767
1768void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1769 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1770}
1771
locke-lunargd556cc32019-09-17 01:21:23 -06001772void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1773 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001774 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001775 if (queue_state) {
1776 queue_state->Retire();
1777 }
locke-lunargd556cc32019-09-17 01:21:23 -06001778}
1779
1780void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1781 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001782 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001783 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001784 }
1785}
1786
1787void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001788 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001789}
1790
1791void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1792 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001793 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001794}
1795
1796void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001797 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001798}
1799
1800void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1801 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001802 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001803}
1804
locke-lunargd556cc32019-09-17 01:21:23 -06001805void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001806 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001807 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001808 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001809 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001810 if (mem_state) {
1811 buffer_state->SetMemBinding(mem_state, memoryOffset);
1812 }
locke-lunargd556cc32019-09-17 01:21:23 -06001813 }
1814}
1815
1816void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1817 VkDeviceSize memoryOffset, VkResult result) {
1818 if (VK_SUCCESS != result) return;
1819 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1820}
1821
1822void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001823 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001824 for (uint32_t i = 0; i < bindInfoCount; i++) {
1825 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1826 }
1827}
1828
1829void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001830 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001831 for (uint32_t i = 0; i < bindInfoCount; i++) {
1832 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1833 }
1834}
1835
Spencer Fricke6c127102020-04-16 06:25:20 -07001836void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001837 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001838 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001839 buffer_state->memory_requirements_checked = true;
1840 }
1841}
1842
1843void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1844 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001845 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001846}
1847
1848void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001849 const VkBufferMemoryRequirementsInfo2 *pInfo,
1850 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001851 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001852}
1853
1854void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001855 const VkBufferMemoryRequirementsInfo2 *pInfo,
1856 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001857 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001858}
1859
Spencer Fricke6c127102020-04-16 06:25:20 -07001860void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001861 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001862 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001863 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001864 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001865 if (plane_info != nullptr) {
1866 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001867 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001868 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001869 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001870 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001871 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001872 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001873 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001874 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001875 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001876 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001877 }
locke-lunargd556cc32019-09-17 01:21:23 -06001878 }
1879}
1880
1881void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1882 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001883 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001884}
1885
1886void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1887 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001888 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001889}
1890
1891void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1892 const VkImageMemoryRequirementsInfo2 *pInfo,
1893 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001894 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001895}
1896
locke-lunargd556cc32019-09-17 01:21:23 -06001897void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1898 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1899 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001900 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001901 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001902}
1903
1904void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001905 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1906 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001907 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001908 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001909}
1910
1911void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001912 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1913 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001914 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001915 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001916}
1917
1918void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1919 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001920 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001921}
1922
1923void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1924 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001925 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001926}
1927
1928void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1929 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001930 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001931}
1932
1933void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1934 const VkAllocationCallbacks *pAllocator) {
1935 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001936 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001937 // Any bound cmd buffers are now invalid
1938 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001939 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1940 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1941 custom_border_color_sampler_count--;
1942 }
locke-lunargd556cc32019-09-17 01:21:23 -06001943 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001944 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001945}
1946
1947void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1948 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001949 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001950}
1951
1952void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1953 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001954 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001955}
1956
locke-lunargd556cc32019-09-17 01:21:23 -06001957void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1958 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001959 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1960 if (pool) {
1961 pool->Free(commandBufferCount, pCommandBuffers);
1962 }
locke-lunargd556cc32019-09-17 01:21:23 -06001963}
1964
1965void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1966 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1967 VkResult result) {
1968 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001969 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001970 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001971}
1972
1973void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1974 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1975 VkResult result) {
1976 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001977
1978 uint32_t index_count = 0, n_perf_pass = 0;
1979 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001980 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001981 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001982 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001983
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001984 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001985 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1986 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1987 switch (counter.scope) {
1988 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001989 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001990 break;
1991 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001992 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001993 break;
1994 default:
1995 break;
1996 }
1997 }
1998
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001999 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002000 }
2001
Jeremy Gebben082a9832021-10-28 13:40:11 -06002002 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 -06002003
locke-lunargd556cc32019-09-17 01:21:23 -06002004}
2005
2006void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2007 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002008 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002009}
2010
2011void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2012 VkCommandPoolResetFlags flags, VkResult result) {
2013 if (VK_SUCCESS != result) return;
2014 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002015 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2016 if (pool) {
2017 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002018 }
2019}
2020
2021void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2022 VkResult result) {
2023 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002024 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002025 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002026 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002027 }
2028 }
2029}
2030
locke-lunargd556cc32019-09-17 01:21:23 -06002031void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2032 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002033 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002034}
2035
2036void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2037 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2042 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2043 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002044 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002045}
2046
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002047std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2048 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2049 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2050 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2051}
2052
locke-lunargd556cc32019-09-17 01:21:23 -06002053bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2054 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2055 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002056 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002057 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002058 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2059 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2060 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2061 cgpl_state->pipe_state.reserve(count);
2062 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002063 const auto &create_info = pCreateInfos[i];
2064 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2065 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2066
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002067 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002068 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002069 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002070 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2071 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
ziga-lunarg08c81582022-03-08 17:33:45 +01002072 } else {
ziga-lunarg08c81582022-03-08 17:33:45 +01002073 skip = true;
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002074 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002075 cgpl_state->pipe_state.push_back(
2076 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002077 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002078 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002079}
2080
2081void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2082 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2083 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2084 VkResult result, void *cgpl_state_data) {
2085 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2086 // This API may create pipelines regardless of the return value
2087 for (uint32_t i = 0; i < count; i++) {
2088 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002089 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002090 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002091 }
2092 }
2093 cgpl_state->pipe_state.clear();
2094}
2095
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002096std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2097 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2098 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2099}
2100
locke-lunargd556cc32019-09-17 01:21:23 -06002101bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2102 const VkComputePipelineCreateInfo *pCreateInfos,
2103 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002104 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002105 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2106 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2107 ccpl_state->pipe_state.reserve(count);
2108 for (uint32_t i = 0; i < count; i++) {
2109 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002110 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002111 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002112 }
2113 return false;
2114}
2115
2116void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2117 const VkComputePipelineCreateInfo *pCreateInfos,
2118 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2119 VkResult result, void *ccpl_state_data) {
2120 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2121
2122 // This API may create pipelines regardless of the return value
2123 for (uint32_t i = 0; i < count; i++) {
2124 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002125 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002126 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002127 }
2128 }
2129 ccpl_state->pipe_state.clear();
2130}
2131
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002132std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2133 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2134 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2135}
2136
locke-lunargd556cc32019-09-17 01:21:23 -06002137bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2138 uint32_t count,
2139 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2140 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002141 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002142 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2143 crtpl_state->pipe_state.reserve(count);
2144 for (uint32_t i = 0; i < count; i++) {
2145 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002146 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002147 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002148 }
2149 return false;
2150}
2151
2152void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2153 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2154 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2155 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2156 // This API may create pipelines regardless of the return value
2157 for (uint32_t i = 0; i < count; i++) {
2158 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002159 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002160 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002161 }
2162 }
2163 crtpl_state->pipe_state.clear();
2164}
2165
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002166std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2167 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2168 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2169}
2170
sourav parmarcd5fb182020-07-17 12:58:44 -07002171bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2172 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002173 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2174 const VkAllocationCallbacks *pAllocator,
2175 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002176 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002177 crtpl_state->pipe_state.reserve(count);
2178 for (uint32_t i = 0; i < count; i++) {
2179 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002180 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002181 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002182 }
2183 return false;
2184}
2185
sourav parmarcd5fb182020-07-17 12:58:44 -07002186void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2187 VkPipelineCache pipelineCache, uint32_t count,
2188 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2189 const VkAllocationCallbacks *pAllocator,
2190 VkPipeline *pPipelines, VkResult result,
2191 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002192 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
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 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002197 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002198 }
2199 }
2200 crtpl_state->pipe_state.clear();
2201}
2202
locke-lunargd556cc32019-09-17 01:21:23 -06002203void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2204 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2205 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002206 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002207 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2208 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002209 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002210 }
locke-lunargd556cc32019-09-17 01:21:23 -06002211}
2212
2213void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2214 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2215 const VkAllocationCallbacks *pAllocator,
2216 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2217 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002218 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002219}
2220
locke-lunargd556cc32019-09-17 01:21:23 -06002221void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2222 const VkAllocationCallbacks *pAllocator,
2223 VkPipelineLayout *pPipelineLayout, VkResult result) {
2224 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002225 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002226}
2227
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002228std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2229 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2230 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2231}
2232
locke-lunargd556cc32019-09-17 01:21:23 -06002233void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2234 const VkAllocationCallbacks *pAllocator,
2235 VkDescriptorPool *pDescriptorPool, VkResult result) {
2236 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002237 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002238}
2239
2240void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2241 VkDescriptorPoolResetFlags flags, VkResult result) {
2242 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002243 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2244 if (pool) {
2245 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002246 }
locke-lunargd556cc32019-09-17 01:21:23 -06002247}
2248
2249bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2250 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002251 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002252 // Always update common data
2253 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2254 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2255 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2256
2257 return false;
2258}
2259
2260// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2261void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2262 VkDescriptorSet *pDescriptorSets, VkResult result,
2263 void *ads_state_data) {
2264 if (VK_SUCCESS != result) return;
2265 // All the updates are contained in a single cvdescriptorset function
2266 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2267 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002268 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2269 if (pool_state) {
2270 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2271 }
locke-lunargd556cc32019-09-17 01:21:23 -06002272}
2273
2274void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2275 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002276 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2277 if (pool_state) {
2278 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002279 }
2280}
2281
2282void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2283 const VkWriteDescriptorSet *pDescriptorWrites,
2284 uint32_t descriptorCopyCount,
2285 const VkCopyDescriptorSet *pDescriptorCopies) {
2286 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2287 pDescriptorCopies);
2288}
2289
2290void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002291 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002292 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002293 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002294 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002295 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002296 }
2297}
2298
locke-lunargd556cc32019-09-17 01:21:23 -06002299void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2300 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002301 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002302 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002303
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002304 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002305}
2306
2307void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002308 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002309 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002310
2311 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002312}
2313
2314void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2315 VkResult result) {
2316 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002317 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2318 if (cb_state) {
2319 cb_state->Reset();
2320 }
locke-lunargd556cc32019-09-17 01:21:23 -06002321 }
2322}
2323
2324CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2325 // initially assume everything is static state
2326 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2327
2328 if (ds) {
2329 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002330 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002331 }
2332 }
locke-lunargd556cc32019-09-17 01:21:23 -06002333 return flags;
2334}
2335
2336// Validation cache:
2337// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002338
2339void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2340 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002341 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002342 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002343 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002344
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002345 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002346 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002347 const auto &create_info = pipe_state->create_info.graphics;
2348 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2349 const auto *viewport_state = create_info.pViewportState;
2350 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002351 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002352 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002353 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002354 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002355
2356 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002357 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2358 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002359 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002360 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002361 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002362 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002363 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002364 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002365
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002366 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002367 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2368 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2369 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002370 if (!has_dynamic_viewport_count) {
2371 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002372 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002373 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2374 // should become = ~uint32_t(0) if the other interpretation is correct.
2375 }
2376 }
2377 if (!has_dynamic_scissor_count) {
2378 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002379 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002380 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2381 // should become = ~uint32_t(0) if the other interpretation is correct.
2382 }
2383 }
locke-lunargd556cc32019-09-17 01:21:23 -06002384 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002385 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002386 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002387 if (!disabled[command_buffer_state]) {
2388 cb_state->AddChild(pipe_state);
2389 }
locke-lunargd556cc32019-09-17 01:21:23 -06002390}
2391
2392void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2393 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002394 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002395 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002396 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2397 cb_state->viewportMask |= bits;
2398 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002399
2400 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2401 for (size_t i = 0; i < viewportCount; ++i) {
2402 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2403 }
locke-lunargd556cc32019-09-17 01:21:23 -06002404}
2405
2406void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2407 uint32_t exclusiveScissorCount,
2408 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002409 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002410 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002411 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2412 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002413}
2414
2415void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2416 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002417 if (disabled[command_buffer_state]) return;
2418
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002419 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002420 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002421
2422 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002423 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002424 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002425 }
2426}
2427
2428void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2429 uint32_t viewportCount,
2430 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002431 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002432 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002433 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2434 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002435}
2436
2437void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2438 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2439 const VkAllocationCallbacks *pAllocator,
2440 VkAccelerationStructureNV *pAccelerationStructure,
2441 VkResult result) {
2442 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002443 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002444}
2445
Jeff Bolz95176d02020-04-01 00:36:16 -05002446void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2447 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2448 const VkAllocationCallbacks *pAllocator,
2449 VkAccelerationStructureKHR *pAccelerationStructure,
2450 VkResult result) {
2451 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002452 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2453 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002454}
2455
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002456void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2457 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2458 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2459 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2460 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002461 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002462 if (dst_as_state != nullptr) {
2463 dst_as_state->Build(&pInfos[i]);
2464 }
2465 }
2466}
2467
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002468// helper method for device side acceleration structure builds
2469void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2470 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2471 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2472 if (dst_as_state) {
2473 dst_as_state->Build(&info);
2474 }
2475 if (disabled[command_buffer_state]) {
2476 return;
2477 }
2478 if (dst_as_state) {
2479 cb_state.AddChild(dst_as_state);
2480 }
2481 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2482 if (src_as_state) {
2483 cb_state.AddChild(src_as_state);
2484 }
2485 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2486 if (scratch_buffer) {
2487 cb_state.AddChild(scratch_buffer);
2488 }
2489
2490 for (uint32_t i = 0; i < info.geometryCount; i++) {
2491 // only one of pGeometries and ppGeometries can be non-null
2492 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2493 switch (geom.geometryType) {
2494 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2495 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2496 if (vertex_buffer) {
2497 cb_state.AddChild(vertex_buffer);
2498 }
2499 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2500 if (index_buffer) {
2501 cb_state.AddChild(index_buffer);
2502 }
2503 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2504 if (transform_buffer) {
2505 cb_state.AddChild(transform_buffer);
2506 }
2507 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2508 if (motion_data) {
2509 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2510 if (motion_buffer) {
2511 cb_state.AddChild(motion_buffer);
2512 }
2513 }
2514 } break;
2515 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2516 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2517 if (data_buffer) {
2518 cb_state.AddChild(data_buffer);
2519 }
2520 } break;
2521 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2522 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2523 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2524 // easily ensure that's true.
2525 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2526 if (data_buffer) {
2527 cb_state.AddChild(data_buffer);
2528 }
2529 } break;
2530 default:
2531 break;
2532 }
2533 }
2534}
2535
sourav parmarcd5fb182020-07-17 12:58:44 -07002536void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2537 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2538 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002539 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002540 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002541 return;
2542 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002543 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002544 for (uint32_t i = 0; i < infoCount; i++) {
2545 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002546 }
2547 cb_state->hasBuildAccelerationStructureCmd = true;
2548}
2549
2550void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2551 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2552 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2553 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002554 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2555 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002556 return;
2557 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002558 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002559 for (uint32_t i = 0; i < infoCount; i++) {
2560 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002561 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002562 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2563 if (indirect_buffer) {
2564 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002565 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002566 }
2567 }
2568 cb_state->hasBuildAccelerationStructureCmd = true;
2569}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002570
locke-lunargd556cc32019-09-17 01:21:23 -06002571void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002572 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002573 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002574 if (as_state != nullptr) {
2575 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002576 as_state->memory_requirements_checked = true;
2577 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002578 as_state->build_scratch_memory_requirements_checked = true;
2579 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002580 as_state->update_scratch_memory_requirements_checked = true;
2581 }
2582 }
2583}
2584
sourav parmarcd5fb182020-07-17 12:58:44 -07002585void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2586 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002587 if (VK_SUCCESS != result) return;
2588 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002589 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002590
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002591 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002592 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002593 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002594 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002595 if (mem_state) {
2596 as_state->SetMemBinding(mem_state, info.memoryOffset);
2597 }
locke-lunargd556cc32019-09-17 01:21:23 -06002598
2599 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002600 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002601 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002602 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2603 }
2604 }
2605 }
2606}
2607
2608void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2609 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2610 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002611 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2612 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002613 return;
2614 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002615 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002616
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002617 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002618 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002619 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002620 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002621 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002622 }
locke-lunargd556cc32019-09-17 01:21:23 -06002623 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002624 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002625 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002626 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002627 cb_state->AddChild(src_as_state);
2628 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002629 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2630 if (instance_buffer) {
2631 cb_state->AddChild(instance_buffer);
2632 }
2633 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2634 if (scratch_buffer) {
2635 cb_state->AddChild(scratch_buffer);
2636 }
2637
2638 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2639 const auto& geom = pInfo->pGeometries[i];
2640
2641 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2642 if (vertex_buffer) {
2643 cb_state->AddChild(vertex_buffer);
2644 }
2645 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2646 if (index_buffer) {
2647 cb_state->AddChild(index_buffer);
2648 }
2649 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2650 if (transform_buffer) {
2651 cb_state->AddChild(transform_buffer);
2652 }
2653
2654 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2655 if (aabb_buffer) {
2656 cb_state->AddChild(aabb_buffer);
2657 }
2658 }
2659
locke-lunargd556cc32019-09-17 01:21:23 -06002660 }
2661 cb_state->hasBuildAccelerationStructureCmd = true;
2662}
2663
2664void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2665 VkAccelerationStructureNV dst,
2666 VkAccelerationStructureNV src,
2667 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002668 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002669 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002670 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2671 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002672 if (!disabled[command_buffer_state]) {
2673 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2674 }
locke-lunargd556cc32019-09-17 01:21:23 -06002675 if (dst_as_state != nullptr && src_as_state != nullptr) {
2676 dst_as_state->built = true;
2677 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002678 }
2679 }
2680}
2681
Jeff Bolz95176d02020-04-01 00:36:16 -05002682void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2683 VkAccelerationStructureKHR accelerationStructure,
2684 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002685 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002686}
2687
Jeff Bolz95176d02020-04-01 00:36:16 -05002688void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2689 VkAccelerationStructureNV accelerationStructure,
2690 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002691 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002692}
2693
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002694void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2695 uint32_t viewportCount,
2696 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002697 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002698 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002699}
2700
locke-lunargd556cc32019-09-17 01:21:23 -06002701void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002702 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002703 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002704}
2705
2706void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2707 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002708 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002709 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002710}
2711
2712void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2713 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002714 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002715 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002716}
2717
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002718void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2719 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002720 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002721 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002722 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2723 cb_state->scissorMask |= bits;
2724 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002725}
2726
locke-lunargd556cc32019-09-17 01:21:23 -06002727void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002728 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002729 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002730}
2731
2732void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2733 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002734 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002735 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002736}
2737
2738void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2739 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002740 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002741 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002742}
2743
2744void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2745 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002746 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002747 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002748}
2749
2750void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2751 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002752 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002753 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002754}
2755
locke-lunargd556cc32019-09-17 01:21:23 -06002756// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2757void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2758 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2759 uint32_t firstSet, uint32_t setCount,
2760 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2761 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002762 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002763 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002764 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002765 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002766
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002767 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2768 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002769}
2770
locke-lunargd556cc32019-09-17 01:21:23 -06002771void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2772 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2773 uint32_t set, uint32_t descriptorWriteCount,
2774 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002775 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002776 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002777 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002778}
2779
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002780void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2781 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2782 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002783 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2784 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002785 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002786 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2787 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002788
2789 auto &push_constant_data = cb_state->push_constant_data;
2790 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2791 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002792 cb_state->push_constant_pipeline_layout_set = layout;
2793
2794 auto flags = stageFlags;
2795 uint32_t bit_shift = 0;
2796 while (flags) {
2797 if (flags & 1) {
2798 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2799 const auto it = cb_state->push_constant_data_update.find(flag);
2800
2801 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002802 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002803 }
2804 }
2805 flags = flags >> 1;
2806 ++bit_shift;
2807 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002808 }
2809}
2810
locke-lunargd556cc32019-09-17 01:21:23 -06002811void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2812 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002813 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002814
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002815 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002816 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002817 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002818 cb_state->index_buffer_binding.offset = offset;
2819 cb_state->index_buffer_binding.index_type = indexType;
2820 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002821 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002822 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002823 }
locke-lunargd556cc32019-09-17 01:21:23 -06002824}
2825
2826void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2827 uint32_t bindingCount, const VkBuffer *pBuffers,
2828 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002829 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002830 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002831
2832 uint32_t end = firstBinding + bindingCount;
2833 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2834 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2835 }
2836
2837 for (uint32_t i = 0; i < bindingCount; ++i) {
2838 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002839 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002840 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002841 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2842 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002843 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002844 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002845 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002846 }
locke-lunargd556cc32019-09-17 01:21:23 -06002847 }
2848}
2849
2850void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2851 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002852 if (disabled[command_buffer_state]) return;
2853
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002854 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002855 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002856}
2857
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002858void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2859 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002860 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002861 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002862}
2863
2864void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2865 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002866 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002867 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2868
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002869 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2870 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002871}
2872
Tony-LunarGc43525f2021-11-15 16:12:38 -07002873void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2874 const VkDependencyInfo* pDependencyInfo) {
2875 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2876 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2877
2878 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2879 cb_state->RecordBarriers(*pDependencyInfo);
2880}
2881
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002882void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2883 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002884 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002885 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002886}
2887
2888void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2889 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002890 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002891 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002892}
2893
Tony-LunarGa2662db2021-11-16 07:26:24 -07002894void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2895 VkPipelineStageFlags2 stageMask) {
2896 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2897 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2898}
2899
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002900void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2901 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2902 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2903 uint32_t bufferMemoryBarrierCount,
2904 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2905 uint32_t imageMemoryBarrierCount,
2906 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002907 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2908 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002909 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2910 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002911}
2912
2913void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2914 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002915 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002916 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002917 const auto &dep_info = pDependencyInfos[i];
2918 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2919 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2920 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002921 }
2922}
2923
Tony-LunarG1364cf52021-11-17 16:10:11 -07002924void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2925 const VkDependencyInfo *pDependencyInfos) {
2926 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2927 for (uint32_t i = 0; i < eventCount; i++) {
2928 const auto &dep_info = pDependencyInfos[i];
2929 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2930 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2931 cb_state->RecordBarriers(dep_info);
2932 }
2933}
2934
Jeremy Gebben79649152021-06-22 14:46:24 -06002935void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2936 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2937 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2938 uint32_t bufferMemoryBarrierCount,
2939 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2940 uint32_t imageMemoryBarrierCount,
2941 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002942 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002943 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2944 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2945 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002946}
2947
2948void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2949 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002950 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002951 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2952 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002953}
2954
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002955void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2956 const VkDependencyInfo *pDependencyInfo) {
2957 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2958 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2959 cb_state->RecordBarriers(*pDependencyInfo);
2960}
2961
locke-lunargd556cc32019-09-17 01:21:23 -06002962void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2963 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002964 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002965
locke-lunargd556cc32019-09-17 01:21:23 -06002966 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002967 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002968 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002969 if (!disabled[query_validation]) {
2970 cb_state->BeginQuery(query);
2971 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002972 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002973 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002974 cb_state->AddChild(pool_state);
2975 }
locke-lunargd556cc32019-09-17 01:21:23 -06002976}
2977
2978void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002979 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002980 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002981 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002982 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002983 if (!disabled[query_validation]) {
2984 cb_state->EndQuery(query_obj);
2985 }
2986 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002987 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002988 cb_state->AddChild(pool_state);
2989 }
locke-lunargd556cc32019-09-17 01:21:23 -06002990}
2991
2992void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2993 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002994 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002995 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002996
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002997 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002998 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002999
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003000 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003001 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003002 cb_state->AddChild(pool_state);
3003 }
locke-lunargd556cc32019-09-17 01:21:23 -06003004}
3005
3006void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3007 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3008 VkDeviceSize dstOffset, VkDeviceSize stride,
3009 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003010 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3011
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003012 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003013 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003014 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003015 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003016 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003017 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003018}
3019
3020void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3021 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003022 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003023 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003024}
3025
3026void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3027 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3028 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003029 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003030 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003031}
3032
Tony-LunarGde9936b2021-11-17 15:34:11 -07003033void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3034 VkQueryPool queryPool, uint32_t slot) {
3035 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3036 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3037}
3038
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003039void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3040 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3041 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3042 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003043 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003044 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003045 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003046 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003047 cb_state->AddChild(pool_state);
3048 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003049 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003050}
3051
locke-lunargd556cc32019-09-17 01:21:23 -06003052void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3053 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3054 VkResult result) {
3055 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003056
Jeremy Gebben88f58142021-06-01 10:07:52 -06003057 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003058 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003059 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003060
locke-lunargd556cc32019-09-17 01:21:23 -06003061 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003062 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003063 }
3064 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003065
Jeremy Gebben9f537102021-10-05 16:37:12 -06003066 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003067 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003068}
3069
locke-lunargd556cc32019-09-17 01:21:23 -06003070void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3071 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3072 VkResult result) {
3073 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003074 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003075}
3076
Mike Schuchardt2df08912020-12-15 16:28:09 -08003077void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003078 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3079 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003080 if (VK_SUCCESS != result) return;
3081
Jeremy Gebben082a9832021-10-28 13:40:11 -06003082 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003083}
3084
Mike Schuchardt2df08912020-12-15 16:28:09 -08003085void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003086 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3087 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003088 if (VK_SUCCESS != result) return;
3089
Jeremy Gebben082a9832021-10-28 13:40:11 -06003090 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003091}
3092
locke-lunargd556cc32019-09-17 01:21:23 -06003093void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3094 const VkRenderPassBeginInfo *pRenderPassBegin,
3095 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003096 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003097 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003098}
3099
3100void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3101 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003102 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003103 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003104 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003105}
3106
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003107void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3108 uint32_t counterBufferCount,
3109 const VkBuffer *pCounterBuffers,
3110 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003111 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003112
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003113 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003114 cb_state->transform_feedback_active = true;
3115}
3116
3117void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3118 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3119 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003120 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003121
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003122 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003123 cb_state->transform_feedback_active = false;
3124}
3125
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003126void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3127 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003128 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003129
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003130 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003131 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003132 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3133 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003134}
3135
3136void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003137 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003138
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003139 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003140 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003141 cb_state->conditional_rendering_inside_render_pass = false;
3142 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003143}
3144
amhagana448ea52021-11-02 14:09:14 -04003145void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003146 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003147 cb_state->activeRenderPass = nullptr;
3148}
3149
3150void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3151 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003152 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003153 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3154}
3155
Tony-LunarG40b33882021-12-02 12:40:11 -07003156void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3157 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3158 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3159}
3160
amhagana448ea52021-11-02 14:09:14 -04003161void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3162 RecordCmdEndRenderingRenderPassState(commandBuffer);
3163}
3164
Tony-LunarG40b33882021-12-02 12:40:11 -07003165void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3166 RecordCmdEndRenderingRenderPassState(commandBuffer);
3167}
3168
Tony-LunarG977448c2019-12-02 14:52:02 -07003169void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3170 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003171 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003172 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003173 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003174}
3175
locke-lunargd556cc32019-09-17 01:21:23 -06003176void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003177 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003178 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003179}
3180
3181void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003182 const VkSubpassBeginInfo *pSubpassBeginInfo,
3183 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003184 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003185 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003186}
3187
Tony-LunarG977448c2019-12-02 14:52:02 -07003188void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003189 const VkSubpassBeginInfo *pSubpassBeginInfo,
3190 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003191 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003192 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003193}
3194
3195void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003196 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003197 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003198}
3199
3200void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003201 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003202 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003203 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003204}
3205
Tony-LunarG977448c2019-12-02 14:52:02 -07003206void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003207 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003208 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003209 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003210}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003211
locke-lunargd556cc32019-09-17 01:21:23 -06003212void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3213 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003214 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003215
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003216 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003217}
3218
3219void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3220 VkFlags flags, void **ppData, VkResult result) {
3221 if (VK_SUCCESS != result) return;
3222 RecordMappedMemory(mem, offset, size, ppData);
3223}
3224
3225void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003226 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003227 if (mem_info) {
3228 mem_info->mapped_range = MemRange();
3229 mem_info->p_driver_data = nullptr;
3230 }
3231}
3232
3233void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003234 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003235 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003236 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3237 // See: VUID-vkGetImageSubresourceLayout-image-01895
3238 image_state->fragment_encoder =
3239 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003240 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003241 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003242 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003243 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003244 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003245
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003246 if (!swapchain_image.fake_base_address) {
3247 auto size = image_state->fragment_encoder->TotalSize();
3248 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003249 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003250 // All images bound to this swapchain and index are aliases
3251 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003252 }
3253 } else {
3254 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003255 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003256 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003257 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003258 }
locke-lunargd556cc32019-09-17 01:21:23 -06003259 }
locke-lunargd556cc32019-09-17 01:21:23 -06003260 }
3261}
3262
3263void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3264 VkDeviceSize memoryOffset, VkResult result) {
3265 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003266 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003267 bind_info.image = image;
3268 bind_info.memory = mem;
3269 bind_info.memoryOffset = memoryOffset;
3270 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003271}
3272
3273void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003274 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003275 if (VK_SUCCESS != result) return;
3276 for (uint32_t i = 0; i < bindInfoCount; i++) {
3277 UpdateBindImageMemoryState(pBindInfos[i]);
3278 }
3279}
3280
3281void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003282 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003283 if (VK_SUCCESS != result) return;
3284 for (uint32_t i = 0; i < bindInfoCount; i++) {
3285 UpdateBindImageMemoryState(pBindInfos[i]);
3286 }
3287}
3288
3289void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003290 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003291 if (event_state) {
3292 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3293 }
locke-lunargd556cc32019-09-17 01:21:23 -06003294}
3295
3296void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3297 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3298 VkResult result) {
3299 if (VK_SUCCESS != result) return;
3300 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3301 pImportSemaphoreFdInfo->flags);
3302}
3303
3304void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003305 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003306 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003307 if (semaphore_state) {
3308 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003309 }
3310}
3311
3312#ifdef VK_USE_PLATFORM_WIN32_KHR
3313void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3314 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3315 if (VK_SUCCESS != result) return;
3316 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3317 pImportSemaphoreWin32HandleInfo->flags);
3318}
3319
3320void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3321 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3322 HANDLE *pHandle, VkResult result) {
3323 if (VK_SUCCESS != result) return;
3324 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3325}
3326
3327void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3328 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3329 if (VK_SUCCESS != result) return;
3330 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3331 pImportFenceWin32HandleInfo->flags);
3332}
3333
3334void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3335 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3336 HANDLE *pHandle, VkResult result) {
3337 if (VK_SUCCESS != result) return;
3338 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3339}
3340#endif
3341
3342void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3343 VkResult result) {
3344 if (VK_SUCCESS != result) return;
3345 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3346}
3347
Mike Schuchardt2df08912020-12-15 16:28:09 -08003348void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3349 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003350 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003351
3352 if (fence_node) {
3353 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003354 }
3355}
3356
3357void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3358 VkResult result) {
3359 if (VK_SUCCESS != result) return;
3360 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3361}
3362
Mike Schuchardt2df08912020-12-15 16:28:09 -08003363void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003364 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003365 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003366 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003367 }
3368}
3369
3370void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3371 VkResult result) {
3372 if (VK_SUCCESS != result) return;
3373 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3374}
3375
3376void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3377 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3378 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003379 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003380}
3381
3382void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003383 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003384 SWAPCHAIN_NODE *old_swapchain_state) {
3385 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003386 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003387 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003388 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003389 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3390 surface_state->AddParent(swapchain.get());
3391 surface_state->swapchain = swapchain.get();
3392 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003393 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003394 } else {
3395 surface_state->swapchain = nullptr;
3396 }
3397 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003398 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003399 if (old_swapchain_state) {
3400 old_swapchain_state->retired = true;
3401 }
3402 return;
3403}
3404
3405void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3406 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3407 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003408 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003409 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003410 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003411}
3412
3413void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3414 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003415 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003416}
3417
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003418void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3419 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3420 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3421 VkResult result) {
3422 if (VK_SUCCESS != result) return;
3423 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003424 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003425}
3426
locke-lunargd556cc32019-09-17 01:21:23 -06003427void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003428 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003429 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003430 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3431 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3432 if (semaphore_state) {
3433 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003434 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003435 }
3436
3437 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3438 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3439 // 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
3440 // confused itself just as much.
3441 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3442 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3443 // Mark the image as having been released to the WSI
3444 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3445 if (swapchain_data) {
3446 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3447 if (present_id_info) {
3448 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3449 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3450 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003451 }
3452 }
locke-lunargd556cc32019-09-17 01:21:23 -06003453 }
locke-lunargd556cc32019-09-17 01:21:23 -06003454}
3455
3456void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3457 const VkSwapchainCreateInfoKHR *pCreateInfos,
3458 const VkAllocationCallbacks *pAllocator,
3459 VkSwapchainKHR *pSwapchains, VkResult result) {
3460 if (pCreateInfos) {
3461 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003462 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003463 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003464 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3465 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003466 }
3467 }
3468}
3469
3470void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3471 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003472 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003473 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003474 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3475 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003476 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003477 }
3478
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003479 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003480 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003481 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3482 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003483 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003484 }
3485
3486 // Mark the image as acquired.
3487 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3488 if (swapchain_data) {
3489 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003490 }
3491}
3492
3493void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3494 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3495 VkResult result) {
3496 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3497 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3498}
3499
3500void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3501 uint32_t *pImageIndex, VkResult result) {
3502 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3503 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3504 pAcquireInfo->fence, pImageIndex);
3505}
3506
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003507std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3508 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3509}
3510
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003511void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3512 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3513 VkResult result) {
3514 if (result != VK_SUCCESS) {
3515 return;
3516 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003517 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003518 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003519 // this can fail if the allocator fails
3520 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3521 if (result != VK_SUCCESS) {
3522 return;
3523 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003524 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003525 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3526 if (result != VK_SUCCESS) {
3527 return;
3528 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003529
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003530 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003531 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003532 }
3533}
3534
3535// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003536static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003537 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003538}
3539
3540void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3541 uint32_t *pQueueFamilyPropertyCount,
3542 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003543 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3544 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003545 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003546}
3547
3548void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003549 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003550 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3551 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003552 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003553}
3554
3555void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003556 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003557 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3558 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003559 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003560}
3561void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3562 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003563 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003564}
3565
Jeremy Gebben082a9832021-10-28 13:40:11 -06003566void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003567
3568void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3569 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3570 const VkAllocationCallbacks *pAllocator,
3571 VkSurfaceKHR *pSurface, VkResult result) {
3572 if (VK_SUCCESS != result) return;
3573 RecordVulkanSurface(pSurface);
3574}
3575
3576#ifdef VK_USE_PLATFORM_ANDROID_KHR
3577void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3578 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3579 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3580 VkResult result) {
3581 if (VK_SUCCESS != result) return;
3582 RecordVulkanSurface(pSurface);
3583}
3584#endif // VK_USE_PLATFORM_ANDROID_KHR
3585
3586#ifdef VK_USE_PLATFORM_IOS_MVK
3587void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3588 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3589 VkResult result) {
3590 if (VK_SUCCESS != result) return;
3591 RecordVulkanSurface(pSurface);
3592}
3593#endif // VK_USE_PLATFORM_IOS_MVK
3594
3595#ifdef VK_USE_PLATFORM_MACOS_MVK
3596void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3597 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3598 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3599 VkResult result) {
3600 if (VK_SUCCESS != result) return;
3601 RecordVulkanSurface(pSurface);
3602}
3603#endif // VK_USE_PLATFORM_MACOS_MVK
3604
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003605#ifdef VK_USE_PLATFORM_METAL_EXT
3606void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3607 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3608 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3609 VkResult result) {
3610 if (VK_SUCCESS != result) return;
3611 RecordVulkanSurface(pSurface);
3612}
3613#endif // VK_USE_PLATFORM_METAL_EXT
3614
locke-lunargd556cc32019-09-17 01:21:23 -06003615#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3616void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3617 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3618 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3619 VkResult result) {
3620 if (VK_SUCCESS != result) return;
3621 RecordVulkanSurface(pSurface);
3622}
3623#endif // VK_USE_PLATFORM_WAYLAND_KHR
3624
3625#ifdef VK_USE_PLATFORM_WIN32_KHR
3626void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3627 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3628 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3629 VkResult result) {
3630 if (VK_SUCCESS != result) return;
3631 RecordVulkanSurface(pSurface);
3632}
3633#endif // VK_USE_PLATFORM_WIN32_KHR
3634
3635#ifdef VK_USE_PLATFORM_XCB_KHR
3636void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3637 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3638 VkResult result) {
3639 if (VK_SUCCESS != result) return;
3640 RecordVulkanSurface(pSurface);
3641}
3642#endif // VK_USE_PLATFORM_XCB_KHR
3643
3644#ifdef VK_USE_PLATFORM_XLIB_KHR
3645void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3646 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3647 VkResult result) {
3648 if (VK_SUCCESS != result) return;
3649 RecordVulkanSurface(pSurface);
3650}
3651#endif // VK_USE_PLATFORM_XLIB_KHR
3652
Niklas Haas8b84af12020-04-19 22:20:11 +02003653void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3654 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3655 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3656 VkResult result) {
3657 if (VK_SUCCESS != result) return;
3658 RecordVulkanSurface(pSurface);
3659}
3660
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003661void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3662 VkSurfaceKHR surface,
3663 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3664 VkResult result) {
3665 if (VK_SUCCESS != result) return;
3666 auto surface_state = Get<SURFACE_STATE>(surface);
3667 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3668}
3669
3670void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3671 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3672 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3673 if (VK_SUCCESS != result) return;
3674 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3675 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3676}
3677
3678void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3679 VkSurfaceKHR surface,
3680 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3681 VkResult result) {
3682 auto surface_state = Get<SURFACE_STATE>(surface);
3683 VkSurfaceCapabilitiesKHR caps{
3684 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3685 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3686 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3687 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3688 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3689 };
3690 surface_state->SetCapabilities(physicalDevice, caps);
3691}
3692
locke-lunargd556cc32019-09-17 01:21:23 -06003693void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3694 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3695 VkBool32 *pSupported, VkResult result) {
3696 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003697 auto surface_state = Get<SURFACE_STATE>(surface);
3698 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3699}
3700
3701void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3702 VkSurfaceKHR surface,
3703 uint32_t *pPresentModeCount,
3704 VkPresentModeKHR *pPresentModes,
3705 VkResult result) {
3706 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3707
3708 if (pPresentModes) {
3709 auto surface_state = Get<SURFACE_STATE>(surface);
3710 surface_state->SetPresentModes(physicalDevice,
3711 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3712 }
3713}
3714
3715void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3716 uint32_t *pSurfaceFormatCount,
3717 VkSurfaceFormatKHR *pSurfaceFormats,
3718 VkResult result) {
3719 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3720
3721 if (pSurfaceFormats) {
3722 auto surface_state = Get<SURFACE_STATE>(surface);
3723 surface_state->SetFormats(physicalDevice,
3724 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3725 }
3726}
3727
3728void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3729 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3730 uint32_t *pSurfaceFormatCount,
3731 VkSurfaceFormat2KHR *pSurfaceFormats,
3732 VkResult result) {
3733 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3734
3735 if (pSurfaceFormats) {
3736 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3737 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3738 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3739 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3740 }
3741 surface_state->SetFormats(physicalDevice, std::move(fmts));
3742 }
locke-lunargd556cc32019-09-17 01:21:23 -06003743}
3744
locke-lunargd556cc32019-09-17 01:21:23 -06003745void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3746 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003747 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003748 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003749 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3750}
3751
3752void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003753 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003754 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003755 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3756}
3757
3758void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3759 const VkDebugUtilsLabelEXT *pLabelInfo) {
3760 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3761
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003762 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003763 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3764 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003765 cb_state->debug_label = LoggingLabel(pLabelInfo);
3766}
3767
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003768void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3769 uint32_t queueFamilyIndex,
3770 uint32_t *pCounterCount,
3771 VkPerformanceCounterKHR *pCounters) {
3772 if (NULL == pCounters) return;
3773
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003774 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3775 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003776
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003777 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3778 queue_family_counters->counters.resize(*pCounterCount);
3779 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003780
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003781 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003782}
3783
3784void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3785 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3786 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3787 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3788 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3789}
3790
3791void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3792 VkResult result) {
3793 if (result == VK_SUCCESS) performance_lock_acquired = true;
3794}
3795
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003796void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3797 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003798 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003799 cmd_buffer.second->performance_lock_released = true;
3800 }
3801}
3802
locke-lunargd556cc32019-09-17 01:21:23 -06003803void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003804 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003805 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003806 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003807}
3808
3809void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003810 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003811 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003812 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003813}
3814
Mike Schuchardt2df08912020-12-15 16:28:09 -08003815void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3816 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003817 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003818}
3819
Mike Schuchardt2df08912020-12-15 16:28:09 -08003820void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3821 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3822 const VkAllocationCallbacks *pAllocator,
3823 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3824 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003825 if (VK_SUCCESS != result) return;
3826 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3827}
3828
3829void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003830 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3831 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003832 if (VK_SUCCESS != result) return;
3833 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3834}
3835
3836void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003837 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003838 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003839 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3840 assert(template_state);
3841 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003842 // TODO: Record template push descriptor updates
3843 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003844 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003845 }
3846 }
3847}
3848
3849void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3850 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3851 const void *pData) {
3852 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3853}
3854
3855void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003856 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003857 const void *pData) {
3858 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3859}
3860
Mike Schuchardt2df08912020-12-15 16:28:09 -08003861void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3862 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3863 VkPipelineLayout layout, uint32_t set,
3864 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003865 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003866
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003867 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003868 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003869 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003870 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003871 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003872 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003873 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003874 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003875 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003876 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003877 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3878 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003879 }
3880}
3881
3882void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3883 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003884 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003885 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003886 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003887 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003888 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003889 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003890 }
3891}
3892
3893void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3894 uint32_t *pPropertyCount,
3895 VkDisplayPlanePropertiesKHR *pProperties,
3896 VkResult result) {
3897 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3898 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3899}
3900
3901void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3902 uint32_t *pPropertyCount,
3903 VkDisplayPlaneProperties2KHR *pProperties,
3904 VkResult result) {
3905 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3906 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3907}
3908
3909void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3910 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3911 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003912 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003913 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003914 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003915}
3916
3917void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3918 uint32_t query, uint32_t index) {
3919 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003920 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003921 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003922 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003923}
3924
3925void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3926 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003927 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003928
3929 if (create_info->format != VK_FORMAT_UNDEFINED) {
3930 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003931 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003932 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3933 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003934 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003935
Jeremy Gebben082a9832021-10-28 13:40:11 -06003936 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003937}
3938
3939void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3940 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3941 const VkAllocationCallbacks *pAllocator,
3942 VkSamplerYcbcrConversion *pYcbcrConversion,
3943 VkResult result) {
3944 if (VK_SUCCESS != result) return;
3945 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3946}
3947
3948void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3949 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3950 const VkAllocationCallbacks *pAllocator,
3951 VkSamplerYcbcrConversion *pYcbcrConversion,
3952 VkResult result) {
3953 if (VK_SUCCESS != result) return;
3954 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3955}
3956
3957void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3958 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003959 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003960}
3961
3962void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3963 VkSamplerYcbcrConversion ycbcrConversion,
3964 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003965 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003966}
3967
Tony-LunarG977448c2019-12-02 14:52:02 -07003968void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3969 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003970 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003971 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003972
3973 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003974 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003975 if (!query_pool_state) return;
3976
3977 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003978 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3979 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003980 auto query_index = firstQuery + i;
3981 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003982 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003983 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003984 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003985 }
3986 }
locke-lunargd556cc32019-09-17 01:21:23 -06003987 }
3988}
3989
Tony-LunarG977448c2019-12-02 14:52:02 -07003990void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3991 uint32_t queryCount) {
3992 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3993}
3994
3995void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3996 uint32_t queryCount) {
3997 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3998}
3999
locke-lunargd556cc32019-09-17 01:21:23 -06004000void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004001 const UPDATE_TEMPLATE_STATE *template_state,
4002 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004003 // Translate the templated update into a normal update for validation...
4004 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4005 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4006 decoded_update.desc_writes.data(), 0, NULL);
4007}
4008
4009// Update the common AllocateDescriptorSetsData
4010void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004011 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004012 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004013 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004014 if (layout) {
4015 ds_data->layout_nodes[i] = layout;
4016 // Count total descriptors required per type
4017 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4018 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004019 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4020 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004021 }
4022 }
4023 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4024 }
4025}
4026
locke-lunargd556cc32019-09-17 01:21:23 -06004027void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4028 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004029 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004030 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004031}
4032
Tony-LunarG745150c2021-07-02 15:07:31 -06004033void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4034 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4035 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004036 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004037 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004038}
4039
locke-lunargd556cc32019-09-17 01:21:23 -06004040void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4041 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4042 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004043 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004044 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004045}
4046
Tony-LunarG745150c2021-07-02 15:07:31 -06004047void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4048 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4049 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4050 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004051 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004052 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004053}
4054
locke-lunargd556cc32019-09-17 01:21:23 -06004055void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4056 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004057 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004058 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004059 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004060 if (!disabled[command_buffer_state]) {
4061 cb_state->AddChild(buffer_state);
4062 }
locke-lunargd556cc32019-09-17 01:21:23 -06004063}
4064
4065void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4066 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004067 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004068 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004069 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004070 if (!disabled[command_buffer_state]) {
4071 cb_state->AddChild(buffer_state);
4072 }
locke-lunargd556cc32019-09-17 01:21:23 -06004073}
4074
4075void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004076 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004077 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004078}
4079
4080void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4081 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004082 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004083 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004084 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004085 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004086 cb_state->AddChild(buffer_state);
4087 }
locke-lunargd556cc32019-09-17 01:21:23 -06004088}
4089
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004090void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4091 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004092 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004093 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4094}
4095
4096void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4097 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004098 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004099 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4100}
4101
Tony-LunarG977448c2019-12-02 14:52:02 -07004102void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4103 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004104 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004105 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004106 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004107 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004108 auto buffer_state = Get<BUFFER_STATE>(buffer);
4109 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004110 cb_state->AddChild(buffer_state);
4111 cb_state->AddChild(count_buffer_state);
4112 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004113}
4114
locke-lunargd556cc32019-09-17 01:21:23 -06004115void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4116 VkDeviceSize offset, VkBuffer countBuffer,
4117 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4118 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004119 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004120 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004121}
4122
4123void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4124 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4125 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004126 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004127 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004128}
4129
4130void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4131 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004132 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004133 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004134 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004135 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004136 auto buffer_state = Get<BUFFER_STATE>(buffer);
4137 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004138 cb_state->AddChild(buffer_state);
4139 cb_state->AddChild(count_buffer_state);
4140 }
locke-lunargd556cc32019-09-17 01:21:23 -06004141}
4142
4143void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4144 VkDeviceSize offset, VkBuffer countBuffer,
4145 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4146 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004147 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004148 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004149}
4150
4151void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4152 VkDeviceSize offset, VkBuffer countBuffer,
4153 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4154 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004155 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004156 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004157}
4158
4159void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4160 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004161 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004162 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004163}
4164
4165void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4166 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004167 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004168 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004169 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004170 if (!disabled[command_buffer_state] && buffer_state) {
4171 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004172 }
4173}
4174
4175void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4176 VkDeviceSize offset, VkBuffer countBuffer,
4177 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4178 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004179 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004180 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004181 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004182 auto buffer_state = Get<BUFFER_STATE>(buffer);
4183 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004184 if (buffer_state) {
4185 cb_state->AddChild(buffer_state);
4186 }
4187 if (count_buffer_state) {
4188 cb_state->AddChild(count_buffer_state);
4189 }
locke-lunargd556cc32019-09-17 01:21:23 -06004190 }
4191}
4192
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004193void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4194 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4195 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4196 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4197 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4198 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4199 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004200 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004201 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004202 cb_state->hasTraceRaysCmd = true;
4203}
4204
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004205void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4206 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4207 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4208 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4209 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4210 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004211 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004212 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004213 cb_state->hasTraceRaysCmd = true;
4214}
4215
4216void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4217 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4218 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4219 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4220 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4221 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004222 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004223 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004224 cb_state->hasTraceRaysCmd = true;
4225}
4226
locke-lunargd556cc32019-09-17 01:21:23 -06004227void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4228 const VkAllocationCallbacks *pAllocator,
4229 VkShaderModule *pShaderModule, VkResult result,
4230 void *csm_state_data) {
4231 if (VK_SUCCESS != result) return;
4232 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4233
sfricke-samsung45996a42021-09-16 13:45:27 -07004234 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004235 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004236 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4237 csm_state->unique_shader_id)
4238 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004239 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004240}
4241
John Zulauf22b0fbe2019-10-15 06:26:16 -06004242void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4243 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4244 VkResult result) {
4245 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004246 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004247
4248 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4249
4250 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004251 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004252 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004253 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004254
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004255 auto format_features = GetImageFormatFeatures(
4256 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4257 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004258
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004259 auto image_state =
4260 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004261 if (!swapchain_image.fake_base_address) {
4262 auto size = image_state->fragment_encoder->TotalSize();
4263 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004264 }
4265
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004266 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004267 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004268 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004269 }
4270 }
4271
4272 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004273 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4274 }
4275}
sourav parmar35e7a002020-06-09 17:58:44 -07004276
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004277void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4278 const VkCopyAccelerationStructureInfoKHR *pInfo,
4279 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004280 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4281 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004282 if (dst_as_state != nullptr && src_as_state != nullptr) {
4283 dst_as_state->built = true;
4284 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4285 }
4286}
4287
sourav parmar35e7a002020-06-09 17:58:44 -07004288void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4289 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004290 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004291 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004292 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004293 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4294 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004295 if (dst_as_state != nullptr && src_as_state != nullptr) {
4296 dst_as_state->built = true;
4297 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004298 if (!disabled[command_buffer_state]) {
4299 cb_state->AddChild(dst_as_state);
4300 cb_state->AddChild(src_as_state);
4301 }
sourav parmar35e7a002020-06-09 17:58:44 -07004302 }
4303 }
4304}
Piers Daniell39842ee2020-07-10 16:42:33 -06004305
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004306void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4307 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4308 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4309 if (cb_state) {
4310 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4311 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4312 if (!disabled[command_buffer_state]) {
4313 cb_state->AddChild(src_as_state);
4314 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004315 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4316 if (dst_buffer) {
4317 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004318 }
4319 }
4320}
4321
4322void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4323 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4324 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4325 if (cb_state) {
4326 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4327 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004328 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4329 if (buffer_state) {
4330 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004331 }
4332 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4333 cb_state->AddChild(dst_as_state);
4334 }
4335 }
4336}
4337
Piers Daniell39842ee2020-07-10 16:42:33 -06004338void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004339 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004340 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004341}
4342
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004343void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4344 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4345 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4346}
4347
Piers Daniell39842ee2020-07-10 16:42:33 -06004348void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004349 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004350 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004351}
4352
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004353void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4354 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4355 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4356}
4357
Piers Daniell39842ee2020-07-10 16:42:33 -06004358void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4359 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004360 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004361 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004362 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004363}
4364
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004365void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4366 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004367 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004368 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4369 cb_state->primitiveTopology = primitiveTopology;
4370}
4371
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004372void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4373 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004374 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4375 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004376 uint32_t bits = (1u << viewportCount) - 1u;
4377 cb_state->viewportWithCountMask |= bits;
4378 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004379 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004380 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004381
4382 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4383 for (size_t i = 0; i < viewportCount; ++i) {
4384 cb_state->dynamicViewports[i] = pViewports[i];
4385 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004386}
4387
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004388void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4389 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004390 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004391}
4392
4393void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004394 const VkViewport *pViewports) {
4395 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004396}
4397
4398void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4399 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004400 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004401 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004402 uint32_t bits = (1u << scissorCount) - 1u;
4403 cb_state->scissorWithCountMask |= bits;
4404 cb_state->trashedScissorMask &= ~bits;
4405 cb_state->scissorWithCountCount = scissorCount;
4406 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004407}
4408
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004409void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4410 const VkRect2D *pScissors) {
4411 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4412}
4413
4414void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4415 const VkRect2D *pScissors) {
4416 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4417}
4418
4419void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4420 uint32_t bindingCount, const VkBuffer *pBuffers,
4421 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4422 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004423 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004424 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004425
4426 uint32_t end = firstBinding + bindingCount;
4427 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4428 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4429 }
4430
4431 for (uint32_t i = 0; i < bindingCount; ++i) {
4432 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004433 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004434 vertex_buffer_binding.offset = pOffsets[i];
4435 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4436 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4437 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004438 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004439 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004440 }
4441 }
4442}
4443
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004444void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4445 uint32_t bindingCount, const VkBuffer *pBuffers,
4446 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4447 const VkDeviceSize *pStrides) {
4448 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4449 CMD_BINDVERTEXBUFFERS2EXT);
4450}
4451
4452void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4453 uint32_t bindingCount, const VkBuffer *pBuffers,
4454 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4455 const VkDeviceSize *pStrides) {
4456 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4457 CMD_BINDVERTEXBUFFERS2);
4458}
4459
Piers Daniell39842ee2020-07-10 16:42:33 -06004460void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004461 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004462 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004463}
4464
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004465void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4466 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4467 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4468}
4469
Piers Daniell39842ee2020-07-10 16:42:33 -06004470void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004471 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004472 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004473}
4474
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004475void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4476 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4477 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4478}
4479
Piers Daniell39842ee2020-07-10 16:42:33 -06004480void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004481 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004482 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004483}
4484
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004485void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4486 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4487 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4488}
4489
Piers Daniell39842ee2020-07-10 16:42:33 -06004490void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4491 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004492 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004493 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004494}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004495
4496void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4497 VkBool32 depthBoundsTestEnable) {
4498 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4499 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4500}
4501
Piers Daniell39842ee2020-07-10 16:42:33 -06004502void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
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_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004505}
4506
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004507void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4508 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4509 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4510}
4511
Piers Daniell39842ee2020-07-10 16:42:33 -06004512void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4513 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4514 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004515 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004516 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004517}
locke-lunarg4189aa22020-10-21 00:23:48 -06004518
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004519void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4520 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4521 VkCompareOp compareOp) {
4522 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4523 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4524}
4525
locke-lunarg4189aa22020-10-21 00:23:48 -06004526void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4527 uint32_t discardRectangleCount,
4528 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004529 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004530 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004531}
4532
4533void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4534 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004535 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004536 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004537}
4538
4539void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4540 VkCoarseSampleOrderTypeNV sampleOrderType,
4541 uint32_t customSampleOrderCount,
4542 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004543 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004544 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004545}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004546
4547void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004548 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004549 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004550}
4551
4552void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004553 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004554 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004555}
4556
4557void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4558 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004559 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004560 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004561}
4562
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004563void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4564 VkBool32 rasterizerDiscardEnable) {
4565 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4566 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4567}
4568
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004569void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004570 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004571 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004572}
4573
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004574void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4575 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4576 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4577}
4578
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004579void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4580 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004581 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004582 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004583}
Piers Daniell924cd832021-05-18 13:48:47 -06004584
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004585void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4586 VkBool32 primitiveRestartEnable) {
4587 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4588 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4589}
4590
Piers Daniell924cd832021-05-18 13:48:47 -06004591void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4592 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4593 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4594 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004595 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004596 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4597
4598 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4599 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4600 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004601 if (pipeline_state->create_info.graphics.pDynamicState) {
4602 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4603 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004604 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4605 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4606 break;
4607 }
4608 }
4609 }
4610 }
4611 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004612}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004613
ziga-lunarg67b7c392022-03-26 01:45:34 +01004614void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4615 const VkBool32 *pColorWriteEnables) {
4616 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4617 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4618 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4619}
4620
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004621void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004622 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004623 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004624 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004625 // address is used for GPU-AV and ray tracing buffer validation
4626 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004627 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004628 }
4629}
4630
4631void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4632 VkDeviceAddress address) {
4633 RecordGetBufferDeviceAddress(pInfo, address);
4634}
4635
4636void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4637 VkDeviceAddress address) {
4638 RecordGetBufferDeviceAddress(pInfo, address);
4639}
4640
4641void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4642 VkDeviceAddress address) {
4643 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004644}
4645
4646std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4647 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004648 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004649}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004650
4651std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4652 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004653 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004654 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4655}