blob: 51708bb4c0072fddee74dccf6e7025d03d9a51b1 [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
Jeremy Gebben11af9792021-08-20 10:20:09 -060042extern template PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *, const VkRayTracingPipelineCreateInfoKHR *,
43 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&);
44extern template PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *, const VkRayTracingPipelineCreateInfoNV *,
45 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&);
46
Mark Lobodzinskib4ab6ac2020-04-02 13:12:06 -060047void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) {
48 if (add_obj) {
49 instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type));
50 // Call base class
51 ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj);
52 }
53}
54
John Zulauf2bc1fde2020-04-24 15:09:51 -060055// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
56// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060057static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
58 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060059 const VkImageView *attachments = fb_state.createInfo.pAttachments;
60 uint32_t count = fb_state.createInfo.attachmentCount;
61 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070062 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060063 if (framebuffer_attachments) {
64 attachments = framebuffer_attachments->pAttachments;
65 count = framebuffer_attachments->attachmentCount;
66 }
67 }
68 return std::make_pair(count, attachments);
69}
70
John Zulauf64ffe552021-02-06 10:25:07 -070071template <typename ImageViewPointer, typename Get>
72std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
73 const Get &get_fn) {
74 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060075
76 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
77 const auto attachment_count = count_attachment.first;
78 const auto *attachments = count_attachment.second;
79 views.resize(attachment_count, nullptr);
80 for (uint32_t i = 0; i < attachment_count; i++) {
81 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070082 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060083 }
84 }
85 return views;
86}
87
Jeremy Gebben9f537102021-10-05 16:37:12 -060088std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070089 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060090 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070091 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
92}
93
locke-lunargd556cc32019-09-17 01:21:23 -060094#ifdef VK_USE_PLATFORM_ANDROID_KHR
95// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
96// This could also move into a seperate core_validation_android.cpp file... ?
97
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060098template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020099VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600100 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700101 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600102 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700103 // VUID 01894 will catch if not found in map
104 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
105 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600106 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700107 }
locke-lunargd556cc32019-09-17 01:21:23 -0600108 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600109 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -0600110}
111
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700112void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
113 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
114 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200115 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
116 if (ahb_format_props2) {
117 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
118 } else {
119 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
120 if (ahb_format_props) {
121 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
122 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
123 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700124 }
125}
126
locke-lunargd556cc32019-09-17 01:21:23 -0600127#else
128
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600129template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200130VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600131 return 0;
132}
locke-lunargd556cc32019-09-17 01:21:23 -0600133
134#endif // VK_USE_PLATFORM_ANDROID_KHR
135
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200136VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
137 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200138 VkFormatFeatureFlags2KHR format_features = 0;
139
Petr Kraus44f1c482020-04-25 20:09:25 +0200140 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
141 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200142 if (has_format_feature2) {
143 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200144 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200145 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
146
147 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
148
149 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
150 VkImageDrmFormatModifierPropertiesEXT drm_format_props = {
151 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
152 nullptr,
153 };
154
155 // Find the image modifier
156 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
157
158 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
159 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
160 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
161
162 // Second query to have all the modifiers filled
163 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
164
165 // Look for the image modifier in the list
166 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
167 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
168 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
169 break;
170 }
171 }
172 } else {
173 format_features =
174 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
175 }
176 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600177 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
178 nullptr};
179 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200180
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600181 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
182 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
183 nullptr};
184 format_properties_2.pNext = (void *)&drm_properties_list;
185 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
186 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
187 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
188 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
189 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200190
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600191 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
192 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
193 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
194 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200195 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200196 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600197 } else {
198 VkFormatProperties format_properties;
199 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
200 format_features =
201 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200202 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600203 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200204}
205
locke-lunargd556cc32019-09-17 01:21:23 -0600206void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
207 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
208 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200209 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700210 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600211 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600212 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600213 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200214 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
215 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
216 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600217 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600218 Add(std::make_shared<IMAGE_STATE>(this, *pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600219}
220
221void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600222 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600223}
224
225void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
226 VkImageLayout imageLayout, const VkClearColorValue *pColor,
227 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600228 if (disabled[command_buffer_state]) return;
229
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700230 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600231 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600232 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600233 }
234}
235
236void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
237 VkImageLayout imageLayout,
238 const VkClearDepthStencilValue *pDepthStencil,
239 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600240 if (disabled[command_buffer_state]) return;
241
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700242 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600243 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600244 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600245 }
246}
247
248void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
249 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
250 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600251 if (disabled[command_buffer_state]) return;
252
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700253 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600254 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600255}
256
Jeff Leger178b1e52020-10-05 12:22:23 -0400257void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
258 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600259 if (disabled[command_buffer_state]) return;
260
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700261 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600262 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
263 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400264}
265
Tony-LunarGb61514a2021-11-02 12:36:51 -0600266void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
267 if (disabled[command_buffer_state]) return;
268
269 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
270 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
271 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
272}
273
locke-lunargd556cc32019-09-17 01:21:23 -0600274void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
275 VkImageLayout srcImageLayout, VkImage dstImage,
276 VkImageLayout dstImageLayout, uint32_t regionCount,
277 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600278 if (disabled[command_buffer_state]) return;
279
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700280 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600281 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600282}
283
Jeff Leger178b1e52020-10-05 12:22:23 -0400284void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
285 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600286 if (disabled[command_buffer_state]) return;
287
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700288 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600289 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
290 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400291}
292
Tony-LunarG562fc102021-11-12 13:58:35 -0700293void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
294 const VkResolveImageInfo2 *pResolveImageInfo) {
295 if (disabled[command_buffer_state]) return;
296
297 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
298 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
299 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
300}
301
locke-lunargd556cc32019-09-17 01:21:23 -0600302void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
303 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
304 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600305 if (disabled[command_buffer_state]) return;
306
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700307 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600308 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600309}
310
Jeff Leger178b1e52020-10-05 12:22:23 -0400311void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
312 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600313 if (disabled[command_buffer_state]) return;
314
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700315 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600316 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
317 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400318}
319
Tony-LunarG542ae912021-11-04 16:06:44 -0600320void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
321 if (disabled[command_buffer_state]) return;
322
323 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
324 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
325 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
326}
327
locke-lunargd556cc32019-09-17 01:21:23 -0600328void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
329 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
330 VkResult result) {
331 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600332
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600333 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600334
James Rumble2f6e7bb2021-07-13 15:21:20 +0100335 if (pCreateInfo) {
336 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
337 if (opaque_capture_address) {
338 // address is used for GPU-AV and ray tracing buffer validation
339 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebben65975ed2021-10-29 11:16:10 -0600340 buffer_address_map_.insert(opaque_capture_address->opaqueCaptureAddress, buffer_state.get());
James Rumble2f6e7bb2021-07-13 15:21:20 +0100341 }
342 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600343 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600344}
345
346void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
347 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
348 VkResult result) {
349 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600350
Jeremy Gebben9f537102021-10-05 16:37:12 -0600351 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600352
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200353 VkFormatFeatureFlags2KHR buffer_features;
354 if (has_format_feature2) {
355 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
356 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
357 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
358 buffer_features = fmt_props_3.bufferFeatures;
359 } else {
360 VkFormatProperties format_properties;
361 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
362 buffer_features = format_properties.bufferFeatures;
363 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600364
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200365 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600366}
367
368void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
369 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
370 VkResult result) {
371 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600372 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700373
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200374 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600375 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700376 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600377 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700378 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200379 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
380 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
381 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700382 }
383
locke-lunarg9939d4b2020-10-26 20:11:08 -0600384 // 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 -0600385 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600386 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700387 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600388 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700389 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600390 image_format_info.type = image_state->createInfo.imageType;
391 image_format_info.format = image_state->createInfo.format;
392 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600393 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
394 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600395 image_format_info.flags = image_state->createInfo.flags;
396
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600397 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600398
399 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
400 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600401
Jeremy Gebben082a9832021-10-28 13:40:11 -0600402 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600403}
404
405void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
406 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600407 if (disabled[command_buffer_state]) return;
408
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700409 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600410 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600411}
412
Jeff Leger178b1e52020-10-05 12:22:23 -0400413void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600414 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600415 if (disabled[command_buffer_state]) return;
416
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700417 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600418 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
419 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400420}
421
Tony-LunarGef035472021-11-02 10:23:33 -0600422void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
423 if (disabled[command_buffer_state]) return;
424
425 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
426 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
427 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
428}
429
locke-lunargd556cc32019-09-17 01:21:23 -0600430void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
431 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600432 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600433}
434
435void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600436 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600437}
438
439void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
440 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600441 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600442}
443
444void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
445 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600446 if (disabled[command_buffer_state]) return;
447
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700448 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600449 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600450}
451
452void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
453 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
454 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600455 if (disabled[command_buffer_state]) return;
456
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700457 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600458
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600459 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600460}
461
Jeff Leger178b1e52020-10-05 12:22:23 -0400462void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
463 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600464 if (disabled[command_buffer_state]) return;
465
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700466 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600467 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
468 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400469}
470
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700471void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
472 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
473 if (disabled[command_buffer_state]) return;
474
475 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
476 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
477 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
478}
479
locke-lunargd556cc32019-09-17 01:21:23 -0600480void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
481 VkImageLayout dstImageLayout, uint32_t regionCount,
482 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600483 if (disabled[command_buffer_state]) return;
484
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700485 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600486 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600487}
488
Jeff Leger178b1e52020-10-05 12:22:23 -0400489void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
490 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600491 if (disabled[command_buffer_state]) return;
492
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700493 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600494 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
495 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400496}
497
Tony Barbour845d29b2021-11-09 11:43:14 -0700498void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
499 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
500 if (disabled[command_buffer_state]) return;
501
502 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
503 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
504 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
505}
506
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700507// Gets union of all features defined by Potential Format Features
508// 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 +0200509VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
510 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700511
512 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200513 if (has_format_feature2) {
514 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200515 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
516 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200517 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100518
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200519 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100520
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200521 format_features |= fmt_props_3.linearTilingFeatures;
522 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100523
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200524 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
525 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
526 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
527 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
528 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100529
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200530 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
531 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
532 }
533 }
534 } else {
535 VkFormatProperties format_properties;
536 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
537 format_features |= format_properties.linearTilingFeatures;
538 format_features |= format_properties.optimalTilingFeatures;
539
540 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
541 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
542 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
543
544 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
545
546 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
547 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
548 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
549 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
550
551 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
552 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
553 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700554 }
555 }
556 }
557
558 return format_features;
559}
560
locke-lunargd556cc32019-09-17 01:21:23 -0600561void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
562 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
563 VkResult result) {
564 if (VK_SUCCESS != result) return;
565
Locke Linf3873542021-04-26 11:25:10 -0600566 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
567 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
568 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
569
locke-lunargd556cc32019-09-17 01:21:23 -0600570 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
571 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700572 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600573 if (features2) {
574 enabled_features_found = &(features2->features);
575 }
576 }
577
locke-lunargd556cc32019-09-17 01:21:23 -0600578 if (nullptr == enabled_features_found) {
579 state_tracker->enabled_features.core = {};
580 } else {
581 state_tracker->enabled_features.core = *enabled_features_found;
582 }
583
locke-lunargd556cc32019-09-17 01:21:23 -0600584 // Save local link to this device's physical device state
Jeremy Gebben9f537102021-10-05 16:37:12 -0600585 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
locke-lunargd556cc32019-09-17 01:21:23 -0600586
Tony-LunarG273f32f2021-09-28 08:56:30 -0600587 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
588 if (vulkan_13_features) {
589 state_tracker->enabled_features.core13 = *vulkan_13_features;
590 } else {
591 state_tracker->enabled_features.core13 = {};
592 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
593 if (image_robustness_features) {
594 state_tracker->enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
595 }
596
597 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
598 if (inline_uniform_block_features) {
599 state_tracker->enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
600 state_tracker->enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
601 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
602 }
603
604 const auto *pipeline_creation_cache_control_features =
605 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
606 if (pipeline_creation_cache_control_features) {
607 state_tracker->enabled_features.core13.pipelineCreationCacheControl =
608 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
609 }
610
611 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
612 if (private_data_features) {
613 state_tracker->enabled_features.core13.privateData = private_data_features->privateData;
614 }
615
616 const auto *demote_to_helper_invocation_features =
617 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
618 if (demote_to_helper_invocation_features) {
619 state_tracker->enabled_features.core13.shaderDemoteToHelperInvocation =
620 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
621 }
622
623 const auto *terminate_invocation_features =
624 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
625 if (terminate_invocation_features) {
626 state_tracker->enabled_features.core13.shaderTerminateInvocation =
627 terminate_invocation_features->shaderTerminateInvocation;
628 }
629
630 const auto *subgroup_size_control_features =
631 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
632 if (subgroup_size_control_features) {
633 state_tracker->enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
634 state_tracker->enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
635 }
636
637 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
638 if (synchronization2_features) {
639 state_tracker->enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
640 }
641
642 const auto *texture_compression_astchdr_features =
643 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
644 if (texture_compression_astchdr_features) {
645 state_tracker->enabled_features.core13.textureCompressionASTC_HDR =
646 texture_compression_astchdr_features->textureCompressionASTC_HDR;
647 }
648
649 const auto *initialize_workgroup_memory_features =
650 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
651 if (initialize_workgroup_memory_features) {
652 state_tracker->enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
653 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
654 }
655
656 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
657 if (dynamic_rendering_features) {
658 state_tracker->enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
659 }
660
661 const auto *shader_integer_dot_product_features =
662 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
663 if (shader_integer_dot_product_features) {
664 state_tracker->enabled_features.core13.shaderIntegerDotProduct =
665 shader_integer_dot_product_features->shaderIntegerDotProduct;
666 }
667
668 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
669 if (maintenance4_features) {
670 state_tracker->enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
671 }
672 }
673
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700674 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700675 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700676 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700677 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700678 // Set Extension Feature Aliases to false as there is no struct to check
679 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
680 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
681 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
682 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
683 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
684 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800685 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700686
687 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700688
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700689 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700690 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700691 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
692 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
693 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
694 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700695 }
696
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700697 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700698 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700699 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
700 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700701 }
702
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700703 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700704 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700705 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
706 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
707 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
708 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
709 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
710 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
711 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
712 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
713 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
714 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
715 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
716 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
717 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
718 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
719 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
720 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
721 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
722 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
723 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
724 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
725 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
726 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
727 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
728 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
729 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
730 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
731 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
732 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
733 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
734 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
735 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
736 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
737 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
738 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
739 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
740 descriptor_indexing_features->descriptorBindingPartiallyBound;
741 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
742 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
743 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700744 }
745
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700746 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700747 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700748 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700749 }
750
751 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700752 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700753 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700754 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700755 }
756
757 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700758 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700760 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
761 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700762 }
763
764 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700765 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700766 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
768 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700769 }
770
771 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700772 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700773 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700774 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
775 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700776 }
777
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700778 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700779 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700780 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700781 }
782
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700783 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700784 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700785 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700786 }
787
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700788 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700789 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700790 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
791 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
792 buffer_device_address->bufferDeviceAddressCaptureReplay;
793 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
794 buffer_device_address->bufferDeviceAddressMultiDevice;
795 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800796
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700797 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800798 if (atomic_int64_features) {
799 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
800 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
801 }
802
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700803 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800804 if (memory_model_features) {
805 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
806 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
807 memory_model_features->vulkanMemoryModelDeviceScope;
808 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
809 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
810 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700811 }
812
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700813 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700814 if (vulkan_11_features) {
815 state_tracker->enabled_features.core11 = *vulkan_11_features;
816 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700817 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700818
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700819 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820 if (sixteen_bit_storage_features) {
821 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
822 sixteen_bit_storage_features->storageBuffer16BitAccess;
823 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
824 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
825 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
826 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
827 }
828
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700829 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700830 if (multiview_features) {
831 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
832 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
833 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
834 }
835
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700836 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700837 if (variable_pointers_features) {
838 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
839 variable_pointers_features->variablePointersStorageBuffer;
840 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
841 }
842
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700843 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700844 if (protected_memory_features) {
845 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
846 }
847
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700848 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 if (ycbcr_conversion_features) {
850 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
851 }
852
853 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700854 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 if (shader_draw_parameters_features) {
856 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700857 }
858 }
859
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700860 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600861 if (device_group_ci) {
862 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
863 state_tracker->device_group_create_info = *device_group_ci;
864 } else {
865 state_tracker->physical_device_count = 1;
866 }
locke-lunargd556cc32019-09-17 01:21:23 -0600867
sfricke-samsung828e59d2021-08-22 23:20:49 -0700868 // Features from other extensions passesd in create info
869 {
870 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
871 if (exclusive_scissor_features) {
872 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
873 }
locke-lunargd556cc32019-09-17 01:21:23 -0600874
sfricke-samsung828e59d2021-08-22 23:20:49 -0700875 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
876 if (shading_rate_image_features) {
877 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
878 }
locke-lunargd556cc32019-09-17 01:21:23 -0600879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
881 if (mesh_shader_features) {
882 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
883 }
locke-lunargd556cc32019-09-17 01:21:23 -0600884
sfricke-samsung828e59d2021-08-22 23:20:49 -0700885 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
886 if (transform_feedback_features) {
887 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
888 }
locke-lunargd556cc32019-09-17 01:21:23 -0600889
sfricke-samsung828e59d2021-08-22 23:20:49 -0700890 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
891 if (vtx_attrib_div_features) {
892 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
893 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700894
sfricke-samsung828e59d2021-08-22 23:20:49 -0700895 const auto *buffer_device_address_ext_features =
896 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
897 if (buffer_device_address_ext_features) {
898 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
899 }
locke-lunargd556cc32019-09-17 01:21:23 -0600900
sfricke-samsung828e59d2021-08-22 23:20:49 -0700901 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
902 if (cooperative_matrix_features) {
903 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
904 }
locke-lunargd556cc32019-09-17 01:21:23 -0600905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 const auto *compute_shader_derivatives_features =
907 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
908 if (compute_shader_derivatives_features) {
909 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
910 }
locke-lunargd556cc32019-09-17 01:21:23 -0600911
sfricke-samsung828e59d2021-08-22 23:20:49 -0700912 const auto *fragment_shader_barycentric_features =
913 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
914 if (fragment_shader_barycentric_features) {
915 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *shader_image_footprint_features =
919 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
920 if (shader_image_footprint_features) {
921 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
922 }
locke-lunargd556cc32019-09-17 01:21:23 -0600923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *fragment_shader_interlock_features =
925 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
926 if (fragment_shader_interlock_features) {
927 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
928 }
locke-lunargd556cc32019-09-17 01:21:23 -0600929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *texel_buffer_alignment_features =
931 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
932 if (texel_buffer_alignment_features) {
933 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
934 }
locke-lunargd556cc32019-09-17 01:21:23 -0600935
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 const auto *pipeline_exe_props_features =
937 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
938 if (pipeline_exe_props_features) {
939 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *dedicated_allocation_image_aliasing_features =
943 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
944 if (dedicated_allocation_image_aliasing_features) {
945 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
946 *dedicated_allocation_image_aliasing_features;
947 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500948
sfricke-samsung828e59d2021-08-22 23:20:49 -0700949 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
950 if (performance_query_features) {
951 state_tracker->enabled_features.performance_query_features = *performance_query_features;
952 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100953
sfricke-samsung828e59d2021-08-22 23:20:49 -0700954 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
955 if (device_coherent_memory_features) {
956 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
957 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000958
sfricke-samsung828e59d2021-08-22 23:20:49 -0700959 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
960 if (ycbcr_image_array_features) {
961 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
962 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800963
sfricke-samsung828e59d2021-08-22 23:20:49 -0700964 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
965 if (ray_query_features) {
966 state_tracker->enabled_features.ray_query_features = *ray_query_features;
967 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700968
sfricke-samsung828e59d2021-08-22 23:20:49 -0700969 const auto *ray_tracing_pipeline_features =
970 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
971 if (ray_tracing_pipeline_features) {
972 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
973 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700974
sfricke-samsung828e59d2021-08-22 23:20:49 -0700975 const auto *ray_tracing_acceleration_structure_features =
976 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
977 if (ray_tracing_acceleration_structure_features) {
978 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
979 *ray_tracing_acceleration_structure_features;
980 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500981
sfricke-samsung828e59d2021-08-22 23:20:49 -0700982 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
983 if (robustness2_features) {
984 state_tracker->enabled_features.robustness2_features = *robustness2_features;
985 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500986
sfricke-samsung828e59d2021-08-22 23:20:49 -0700987 const auto *fragment_density_map_features =
988 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
989 if (fragment_density_map_features) {
990 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
991 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200992
sfricke-samsung828e59d2021-08-22 23:20:49 -0700993 const auto *fragment_density_map_features2 =
994 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
995 if (fragment_density_map_features2) {
996 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
997 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200998
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1000 if (astc_decode_features) {
1001 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
1002 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001003
sfricke-samsung828e59d2021-08-22 23:20:49 -07001004 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1005 if (custom_border_color_features) {
1006 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
1007 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001008
sfricke-samsung828e59d2021-08-22 23:20:49 -07001009 const auto *fragment_shading_rate_features =
1010 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1011 if (fragment_shading_rate_features) {
1012 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
1013 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001014
sfricke-samsung828e59d2021-08-22 23:20:49 -07001015 const auto *extended_dynamic_state_features =
1016 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1017 if (extended_dynamic_state_features) {
1018 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
1019 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001020
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 const auto *extended_dynamic_state2_features =
1022 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1023 if (extended_dynamic_state2_features) {
1024 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
1025 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001026
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1028 if (multiview_features) {
1029 state_tracker->enabled_features.multiview_features = *multiview_features;
1030 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001031
sfricke-samsung828e59d2021-08-22 23:20:49 -07001032 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1033 if (portability_features) {
1034 state_tracker->enabled_features.portability_subset_features = *portability_features;
1035 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001036
sfricke-samsung828e59d2021-08-22 23:20:49 -07001037 const auto *shader_integer_functions2_features =
1038 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1039 if (shader_integer_functions2_features) {
1040 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1041 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001042
sfricke-samsung828e59d2021-08-22 23:20:49 -07001043 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1044 if (shader_sm_builtins_features) {
1045 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
1046 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001047
sfricke-samsung828e59d2021-08-22 23:20:49 -07001048 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1049 if (shader_atomic_float_features) {
1050 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
1051 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001052
sfricke-samsung828e59d2021-08-22 23:20:49 -07001053 const auto *shader_image_atomic_int64_features =
1054 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1055 if (shader_image_atomic_int64_features) {
1056 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1057 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001058
sfricke-samsung828e59d2021-08-22 23:20:49 -07001059 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1060 if (shader_clock_features) {
1061 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1062 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001063
sfricke-samsung828e59d2021-08-22 23:20:49 -07001064 const auto *conditional_rendering_features =
1065 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1066 if (conditional_rendering_features) {
1067 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1068 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001069
sfricke-samsung828e59d2021-08-22 23:20:49 -07001070 const auto *workgroup_memory_explicit_layout_features =
1071 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1072 if (workgroup_memory_explicit_layout_features) {
1073 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1074 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001075
sfricke-samsung828e59d2021-08-22 23:20:49 -07001076 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1077 if (provoking_vertex_features) {
1078 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1079 }
Locke Linf3873542021-04-26 11:25:10 -06001080
sfricke-samsung828e59d2021-08-22 23:20:49 -07001081 const auto *vertex_input_dynamic_state_features =
1082 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1083 if (vertex_input_dynamic_state_features) {
1084 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1085 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001086
sfricke-samsung828e59d2021-08-22 23:20:49 -07001087 const auto *inherited_viewport_scissor_features =
1088 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1089 if (inherited_viewport_scissor_features) {
1090 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1091 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001092
sfricke-samsung828e59d2021-08-22 23:20:49 -07001093 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1094 if (multi_draw_features) {
1095 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1096 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001097
sfricke-samsung828e59d2021-08-22 23:20:49 -07001098 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1099 if (color_write_features) {
1100 state_tracker->enabled_features.color_write_features = *color_write_features;
1101 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001102
sfricke-samsung828e59d2021-08-22 23:20:49 -07001103 const auto *shader_atomic_float2_features =
1104 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1105 if (shader_atomic_float2_features) {
1106 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1107 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001108
sfricke-samsung828e59d2021-08-22 23:20:49 -07001109 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1110 if (present_id_features) {
1111 state_tracker->enabled_features.present_id_features = *present_id_features;
1112 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001113
sfricke-samsung828e59d2021-08-22 23:20:49 -07001114 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1115 if (present_wait_features) {
1116 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1117 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001118
1119 const auto *ray_tracing_motion_blur_features =
1120 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1121 if (ray_tracing_motion_blur_features) {
1122 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1123 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001124
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001125 const auto *primitive_topology_list_restart_features =
1126 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1127 if (primitive_topology_list_restart_features) {
1128 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1129 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001130
ziga-lunarge1988962021-09-16 13:32:34 +02001131 const auto *zero_initialize_work_group_memory_features =
1132 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1133 if (zero_initialize_work_group_memory_features) {
1134 state_tracker->enabled_features.zero_initialize_work_group_memory_features =
1135 *zero_initialize_work_group_memory_features;
1136 }
1137
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001138 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1139 if (rgba10x6_formats_features) {
1140 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
1141 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001142
Tony-LunarG69604c42021-11-22 16:00:12 -07001143 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1144 if (image_view_min_lod_features) {
1145 state_tracker->enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
1146 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001147 }
1148
locke-lunargd556cc32019-09-17 01:21:23 -06001149 // Store physical device properties and physical device mem limits into CoreChecks structs
1150 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1151 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1152
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001153 {
1154 uint32_t n_props = 0;
1155 std::vector<VkExtensionProperties> props;
1156 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, NULL);
1157 props.resize(n_props);
Tony-LunarG8c380b92022-01-12 13:44:04 -07001158 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001159
1160 for (const auto &ext_prop : props) {
1161 state_tracker->phys_dev_extensions.insert(ext_prop.extensionName);
1162 }
1163
1164 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1165 // a path to grab that information from the physical device. This
1166 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1167 // Vulkan 1.1 (which made this core).
1168 state_tracker->has_format_feature2 =
1169 (state_tracker->api_version >= VK_API_VERSION_1_1 ||
1170 IsExtEnabled(state_tracker->instance_extensions.vk_khr_get_physical_device_properties2)) &&
1171 state_tracker->phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) !=
1172 state_tracker->phys_dev_extensions.end();
1173 }
1174
locke-lunargd556cc32019-09-17 01:21:23 -06001175 const auto &dev_ext = state_tracker->device_extensions;
1176 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1177
Tony-LunarG273f32f2021-09-28 08:56:30 -06001178 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1179 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
sfricke-samsung45996a42021-09-16 13:45:27 -07001180 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
1181 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001182 if (dev_ext.vk_feature_version_1_3)
1183 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_3, &state_tracker->phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001184 } else {
1185 // VkPhysicalDeviceVulkan11Properties
1186 //
1187 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1188
1189 if (dev_ext.vk_khr_multiview) {
1190 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1191 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1192 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1193 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1194 }
1195
1196 if (dev_ext.vk_khr_maintenance3) {
1197 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1198 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1199 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1200 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1201 }
1202
1203 // Some 1.1 properties were added to core without previous extensions
1204 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1205 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1206 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1207 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1208 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1209
1210 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1211 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1212 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1213 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1214
1215 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1216 }
1217
1218 // VkPhysicalDeviceVulkan12Properties
1219 //
1220 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1221
1222 if (dev_ext.vk_ext_descriptor_indexing) {
1223 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1224 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1225 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1226 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1227 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1228 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1229 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1230 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1231 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1232 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1233 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1234 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1235 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1236 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1237 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1238 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1239 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1240 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1241 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1242 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1243 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1244 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1245 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1246 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1247 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1248 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1249 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1250 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1251 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1252 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1253 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1254 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1255 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1256 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1257 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1258 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1259 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1260 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1261 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1262 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1263 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1264 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1265 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1266 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1267 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1268 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1269 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1270 }
1271
1272 if (dev_ext.vk_khr_depth_stencil_resolve) {
1273 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1274 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1275 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1276 depth_stencil_resolve_props.supportedDepthResolveModes;
1277 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1278 depth_stencil_resolve_props.supportedStencilResolveModes;
1279 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1280 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1281 }
1282
1283 if (dev_ext.vk_khr_timeline_semaphore) {
1284 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1285 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1286 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1287 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1288 }
1289
1290 if (dev_ext.vk_ext_sampler_filter_minmax) {
1291 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1292 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1293 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1294 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1295 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1296 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1297 }
1298
1299 if (dev_ext.vk_khr_shader_float_controls) {
1300 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1301 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1302 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1303 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1304 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1305 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1306 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1307 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1308 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1309 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1310 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1311 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1312 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1313 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1314 float_controls_props.shaderDenormFlushToZeroFloat16;
1315 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1316 float_controls_props.shaderDenormFlushToZeroFloat32;
1317 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1318 float_controls_props.shaderDenormFlushToZeroFloat64;
1319 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1320 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1321 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1322 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1323 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1324 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1325 }
locke-lunargd556cc32019-09-17 01:21:23 -06001326 }
1327
sfricke-samsung828e59d2021-08-22 23:20:49 -07001328 // Extensions with properties to extract to DeviceExtensionProperties
1329 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001330 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1331 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1332 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1333 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001334 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001335 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001336 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1337 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001338 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1339 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001340 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001341 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001342 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001343 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001344 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001345 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001346 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001347 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001348 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001349 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001350 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001351 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001352 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001353
sfricke-samsung45996a42021-09-16 13:45:27 -07001354 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001355 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001356 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1357 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001358 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1359 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1360
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001361 uint32_t num_cooperative_matrix_properties = 0;
1362 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1363 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001364 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001365
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001366 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001367 state_tracker->cooperative_matrix_properties.data());
1368 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001369
locke-lunargd556cc32019-09-17 01:21:23 -06001370 // Store queue family data
1371 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1372 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001373 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001374 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1375 state_tracker->device_queue_info_list.push_back(
1376 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001377 }
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001378 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1379 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1380 VkQueue queue = VK_NULL_HANDLE;
1381 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1382 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1383 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1384 get_info.flags = queue_info.flags;
1385 get_info.queueFamilyIndex = queue_info.queue_family_index;
1386 get_info.queueIndex = i;
1387 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1388 } else {
1389 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1390 }
1391 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001392 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001393 }
locke-lunargd556cc32019-09-17 01:21:23 -06001394 }
1395 }
1396}
1397
1398void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1399 if (!device) return;
1400
Jeremy Gebbend177d922021-10-28 13:42:10 -06001401 command_pool_map_.clear();
1402 assert(command_buffer_map_.empty());
1403 pipeline_map_.clear();
1404 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001405
1406 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001407 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001408 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001409 assert(descriptor_set_map_.empty());
1410 desc_template_map_.clear();
1411 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001412 // Because swapchains are associated with Surfaces, which are at instance level,
1413 // they need to be explicitly destroyed here to avoid continued references to
1414 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001415 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001416 entry.second->Destroy();
1417 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001418 swapchain_map_.clear();
1419 image_view_map_.clear();
1420 image_map_.clear();
1421 buffer_view_map_.clear();
1422 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001423 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001424 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001425}
1426
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001427void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1428 VkFence fence, VkResult result) {
1429 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001430 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001431
Jeremy Gebben57642982021-09-14 14:14:55 -06001432 uint64_t early_retire_seq = 0;
1433
1434 if (submitCount == 0) {
1435 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001436 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001437 early_retire_seq = queue_state->Submit(std::move(submission));
1438 }
locke-lunargd556cc32019-09-17 01:21:23 -06001439
1440 // Now process each individual submit
1441 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001442 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001443 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001444 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001445 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001446 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001447 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1448 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1449 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1450 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001451 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001452 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001453
locke-lunargd556cc32019-09-17 01:21:23 -06001454 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001455 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001456 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1457 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1458 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1459 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001460 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001461 }
1462
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001463 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001464 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001465
locke-lunargd556cc32019-09-17 01:21:23 -06001466 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001467 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001468 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001469 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001470 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001471 }
1472 auto submit_seq = queue_state->Submit(std::move(submission));
1473 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001474 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001475
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001476 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001477 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001478 }
1479}
1480
Tony-LunarG26fe2842021-11-16 14:07:59 -07001481void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1482 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001483 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001484 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001485 uint64_t early_retire_seq = 0;
1486 if (submitCount == 0) {
1487 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001488 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001489 early_retire_seq = queue_state->Submit(std::move(submission));
1490 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001491
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001492 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1493 CB_SUBMISSION submission;
1494 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001495 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1496 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001497 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001498 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001499 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1500 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001501 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001502 }
1503 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1504 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1505
1506 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001507 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001508 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001509 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001510 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001511 }
1512 auto submit_seq = queue_state->Submit(std::move(submission));
1513 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001514 }
locke-lunargd556cc32019-09-17 01:21:23 -06001515 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001516 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001517 }
1518}
1519
Tony-LunarG26fe2842021-11-16 14:07:59 -07001520void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1521 VkFence fence, VkResult result) {
1522 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1523}
1524
1525void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1526 VkFence fence, VkResult result) {
1527 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1528}
1529
locke-lunargd556cc32019-09-17 01:21:23 -06001530void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1531 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1532 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001533 if (VK_SUCCESS != result) {
1534 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001535 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001536 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1537 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1538 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1539
1540 layer_data::optional<DedicatedBinding> dedicated_binding;
1541
1542 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1543 if (dedicated) {
1544 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001545 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001546 assert(buffer_state);
1547 if (!buffer_state) {
1548 return;
1549 }
1550 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1551 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001552 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001553 assert(image_state);
1554 if (!image_state) {
1555 return;
1556 }
1557 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1558 }
1559 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001560 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1561 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001562 return;
1563}
1564
1565void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001566 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001567 if (mem_info) {
1568 fake_memory.Free(mem_info->fake_base_address);
1569 }
1570 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001571}
1572
1573void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1574 VkFence fence, VkResult result) {
1575 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001576 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001577
Jeremy Gebben57642982021-09-14 14:14:55 -06001578 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001579
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001580 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1581 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001582 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001583 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1584 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1585 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001586 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001587 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001588 if (buffer_state && mem_state) {
1589 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1590 }
locke-lunargd556cc32019-09-17 01:21:23 -06001591 }
1592 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001593 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1594 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1595 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001596 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001597 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001598 if (image_state && mem_state) {
1599 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1600 }
locke-lunargd556cc32019-09-17 01:21:23 -06001601 }
1602 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001603 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1604 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1605 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001606 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1607 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001608 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001609 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001610 if (image_state && mem_state) {
1611 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1612 }
locke-lunargd556cc32019-09-17 01:21:23 -06001613 }
1614 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001615 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001616 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001617 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001618 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001619 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001620 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001621 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001622 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001623 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001624 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001625 auto submit_seq = queue_state->Submit(std::move(submission));
1626 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001627 }
1628
1629 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001630 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001631 }
1632}
1633
1634void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1635 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1636 VkResult result) {
1637 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001638 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001639}
1640
Mike Schuchardt2df08912020-12-15 16:28:09 -08001641void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1642 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001643 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1644 if (semaphore_state) {
1645 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001646 }
1647}
1648
Mike Schuchardt2df08912020-12-15 16:28:09 -08001649void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001650 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001651 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001652 if (semaphore_state) {
1653 semaphore_state->RetireTimeline(pSignalInfo->value);
1654 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001655}
1656
locke-lunargd556cc32019-09-17 01:21:23 -06001657void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001658 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001659 if (mem_info) {
1660 mem_info->mapped_range.offset = offset;
1661 mem_info->mapped_range.size = size;
1662 mem_info->p_driver_data = *ppData;
1663 }
1664}
1665
locke-lunargd556cc32019-09-17 01:21:23 -06001666void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1667 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1668 if (VK_SUCCESS != result) return;
1669
1670 // When we know that all fences are complete we can clean/remove their CBs
1671 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1672 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001673 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001674 if (fence_state) {
1675 fence_state->Retire();
1676 }
locke-lunargd556cc32019-09-17 01:21:23 -06001677 }
1678 }
1679 // NOTE : Alternate case not handled here is when some fences have completed. In
1680 // this case for app to guarantee which fences completed it will have to call
1681 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1682}
1683
John Zulauff89de662020-04-13 18:57:34 -06001684void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1685 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001686 if (VK_SUCCESS != result) return;
1687
Jeremy Gebben15332642021-12-15 19:33:15 -07001688 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1689 // the application calls vkGetSemaphoreCounterValue() on each of them.
1690 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1691 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1692 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1693 if (semaphore_state) {
1694 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1695 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001696 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001697 }
1698}
1699
John Zulauff89de662020-04-13 18:57:34 -06001700void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1701 VkResult result) {
1702 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1703}
1704
1705void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1706 uint64_t timeout, VkResult result) {
1707 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1708}
1709
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001710void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1711 VkResult result) {
1712 if (VK_SUCCESS != result) return;
1713
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001714 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001715 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001716 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001717 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001718}
1719
1720void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1721 VkResult result) {
1722 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1723}
1724void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1725 VkResult result) {
1726 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1727}
1728
locke-lunargd556cc32019-09-17 01:21:23 -06001729void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1730 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001731 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001732 if (fence_state) {
1733 fence_state->Retire();
1734 }
locke-lunargd556cc32019-09-17 01:21:23 -06001735}
1736
Yilong Lice03a312022-01-02 02:08:35 -08001737void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1738 if (Get<QUEUE_STATE>(queue) == nullptr) {
1739 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1740 }
1741}
1742
1743void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1744 VkQueue *pQueue) {
1745 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1746}
1747
1748void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1749 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1750}
1751
locke-lunargd556cc32019-09-17 01:21:23 -06001752void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1753 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001754 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001755 if (queue_state) {
1756 queue_state->Retire();
1757 }
locke-lunargd556cc32019-09-17 01:21:23 -06001758}
1759
1760void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1761 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001762 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001763 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001764 }
1765}
1766
1767void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001768 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001769}
1770
1771void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1772 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001773 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001774}
1775
1776void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001777 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001778}
1779
1780void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1781 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001782 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001783}
1784
locke-lunargd556cc32019-09-17 01:21:23 -06001785void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001786 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001787 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001788 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001789 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001790 if (mem_state) {
1791 buffer_state->SetMemBinding(mem_state, memoryOffset);
1792 }
locke-lunargd556cc32019-09-17 01:21:23 -06001793 }
1794}
1795
1796void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1797 VkDeviceSize memoryOffset, VkResult result) {
1798 if (VK_SUCCESS != result) return;
1799 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1800}
1801
1802void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001803 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001804 for (uint32_t i = 0; i < bindInfoCount; i++) {
1805 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1806 }
1807}
1808
1809void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001810 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001811 for (uint32_t i = 0; i < bindInfoCount; i++) {
1812 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1813 }
1814}
1815
Spencer Fricke6c127102020-04-16 06:25:20 -07001816void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001817 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001818 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001819 buffer_state->memory_requirements_checked = true;
1820 }
1821}
1822
1823void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1824 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001825 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001826}
1827
1828void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001829 const VkBufferMemoryRequirementsInfo2 *pInfo,
1830 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001831 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001832}
1833
1834void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001835 const VkBufferMemoryRequirementsInfo2 *pInfo,
1836 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001837 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001838}
1839
Spencer Fricke6c127102020-04-16 06:25:20 -07001840void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001841 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001842 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001843 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001844 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001845 if (plane_info != nullptr) {
1846 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001847 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001848 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001849 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001850 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001851 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001852 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001853 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001854 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001855 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001856 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001857 }
locke-lunargd556cc32019-09-17 01:21:23 -06001858 }
1859}
1860
1861void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1862 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001863 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001864}
1865
1866void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1867 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001868 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001869}
1870
1871void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1872 const VkImageMemoryRequirementsInfo2 *pInfo,
1873 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001874 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001875}
1876
locke-lunargd556cc32019-09-17 01:21:23 -06001877void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1878 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1879 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001880 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001881 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001882}
1883
1884void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001885 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1886 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001887 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001888 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001889}
1890
1891void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001892 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1893 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001894 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001895 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001896}
1897
1898void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1899 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001900 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001901}
1902
1903void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1904 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001905 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001906}
1907
1908void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1909 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001910 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001911}
1912
1913void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1914 const VkAllocationCallbacks *pAllocator) {
1915 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001916 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001917 // Any bound cmd buffers are now invalid
1918 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001919 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1920 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1921 custom_border_color_sampler_count--;
1922 }
locke-lunargd556cc32019-09-17 01:21:23 -06001923 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001924 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001925}
1926
1927void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1928 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001929 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001930}
1931
1932void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1933 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001934 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001935}
1936
locke-lunargd556cc32019-09-17 01:21:23 -06001937void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1938 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001939 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1940 if (pool) {
1941 pool->Free(commandBufferCount, pCommandBuffers);
1942 }
locke-lunargd556cc32019-09-17 01:21:23 -06001943}
1944
1945void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1946 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1947 VkResult result) {
1948 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001949 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001950 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001951}
1952
1953void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1954 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1955 VkResult result) {
1956 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001957
1958 uint32_t index_count = 0, n_perf_pass = 0;
1959 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001960 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001961 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001962 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001963
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001964 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001965 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1966 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1967 switch (counter.scope) {
1968 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001969 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001970 break;
1971 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001972 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001973 break;
1974 default:
1975 break;
1976 }
1977 }
1978
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001979 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001980 }
1981
Jeremy Gebben082a9832021-10-28 13:40:11 -06001982 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 -06001983
locke-lunargd556cc32019-09-17 01:21:23 -06001984}
1985
1986void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1987 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001988 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001989}
1990
1991void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
1992 VkCommandPoolResetFlags flags, VkResult result) {
1993 if (VK_SUCCESS != result) return;
1994 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001995 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1996 if (pool) {
1997 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001998 }
1999}
2000
2001void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2002 VkResult result) {
2003 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002004 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002005 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002006 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002007 }
2008 }
2009}
2010
locke-lunargd556cc32019-09-17 01:21:23 -06002011void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2012 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002013 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002014}
2015
2016void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2017 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002018 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002019}
2020
2021void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2022 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2023 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002024 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002025}
2026
2027bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2028 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2029 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002030 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002031 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2032 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2033 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2034 cgpl_state->pipe_state.reserve(count);
2035 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002036 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002037 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
2038 Get<RENDER_PASS_STATE>(pCreateInfos[i].renderPass),
2039 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Tony-LunarG273f32f2021-09-28 08:56:30 -06002040 } else if (enabled_features.core13.dynamicRendering) {
Tony-LunarG40b33882021-12-02 12:40:11 -07002041 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(pCreateInfos[i].pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002042 cgpl_state->pipe_state.push_back(
2043 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], std::make_shared<RENDER_PASS_STATE>(dynamic_rendering),
Jeremy Gebben9f537102021-10-05 16:37:12 -06002044 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002045 }
locke-lunargd556cc32019-09-17 01:21:23 -06002046 }
2047 return false;
2048}
2049
2050void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2051 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2052 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2053 VkResult result, void *cgpl_state_data) {
2054 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2055 // This API may create pipelines regardless of the return value
2056 for (uint32_t i = 0; i < count; i++) {
2057 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002058 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002059 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002060 }
2061 }
2062 cgpl_state->pipe_state.clear();
2063}
2064
2065bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2066 const VkComputePipelineCreateInfo *pCreateInfos,
2067 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002068 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002069 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2070 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2071 ccpl_state->pipe_state.reserve(count);
2072 for (uint32_t i = 0; i < count; i++) {
2073 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002074 ccpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002075 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002076 }
2077 return false;
2078}
2079
2080void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2081 const VkComputePipelineCreateInfo *pCreateInfos,
2082 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2083 VkResult result, void *ccpl_state_data) {
2084 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2085
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 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002090 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002091 }
2092 }
2093 ccpl_state->pipe_state.clear();
2094}
2095
2096bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2097 uint32_t count,
2098 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2099 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002100 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002101 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2102 crtpl_state->pipe_state.reserve(count);
2103 for (uint32_t i = 0; i < count; i++) {
2104 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002105 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002106 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002107 }
2108 return false;
2109}
2110
2111void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2112 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2113 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2114 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2115 // This API may create pipelines regardless of the return value
2116 for (uint32_t i = 0; i < count; i++) {
2117 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002118 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002119 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002120 }
2121 }
2122 crtpl_state->pipe_state.clear();
2123}
2124
sourav parmarcd5fb182020-07-17 12:58:44 -07002125bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2126 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002127 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2128 const VkAllocationCallbacks *pAllocator,
2129 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002130 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002131 crtpl_state->pipe_state.reserve(count);
2132 for (uint32_t i = 0; i < count; i++) {
2133 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002134 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002135 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002136 }
2137 return false;
2138}
2139
sourav parmarcd5fb182020-07-17 12:58:44 -07002140void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2141 VkPipelineCache pipelineCache, uint32_t count,
2142 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2143 const VkAllocationCallbacks *pAllocator,
2144 VkPipeline *pPipelines, VkResult result,
2145 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002146 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2147 // This API may create pipelines regardless of the return value
2148 for (uint32_t i = 0; i < count; i++) {
2149 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002150 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002151 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002152 }
2153 }
2154 crtpl_state->pipe_state.clear();
2155}
2156
locke-lunargd556cc32019-09-17 01:21:23 -06002157void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2158 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2159 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002160 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002161 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2162 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002163 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002164 }
locke-lunargd556cc32019-09-17 01:21:23 -06002165}
2166
2167void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2168 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2169 const VkAllocationCallbacks *pAllocator,
2170 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2171 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002172 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002173}
2174
locke-lunargd556cc32019-09-17 01:21:23 -06002175void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2176 const VkAllocationCallbacks *pAllocator,
2177 VkPipelineLayout *pPipelineLayout, VkResult result) {
2178 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002179 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002180}
2181
2182void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2183 const VkAllocationCallbacks *pAllocator,
2184 VkDescriptorPool *pDescriptorPool, VkResult result) {
2185 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002186 Add(std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002187}
2188
2189void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2190 VkDescriptorPoolResetFlags flags, VkResult result) {
2191 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002192 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2193 if (pool) {
2194 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002195 }
locke-lunargd556cc32019-09-17 01:21:23 -06002196}
2197
2198bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2199 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002200 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002201 // Always update common data
2202 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2203 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2204 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2205
2206 return false;
2207}
2208
2209// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2210void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2211 VkDescriptorSet *pDescriptorSets, VkResult result,
2212 void *ads_state_data) {
2213 if (VK_SUCCESS != result) return;
2214 // All the updates are contained in a single cvdescriptorset function
2215 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2216 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002217 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2218 if (pool_state) {
2219 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2220 }
locke-lunargd556cc32019-09-17 01:21:23 -06002221}
2222
2223void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2224 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002225 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2226 if (pool_state) {
2227 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002228 }
2229}
2230
2231void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2232 const VkWriteDescriptorSet *pDescriptorWrites,
2233 uint32_t descriptorCopyCount,
2234 const VkCopyDescriptorSet *pDescriptorCopies) {
2235 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2236 pDescriptorCopies);
2237}
2238
2239void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002240 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002241 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002242 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002243 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002244 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002245 }
2246}
2247
locke-lunargd556cc32019-09-17 01:21:23 -06002248void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2249 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002250 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002251 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002252
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002253 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002254}
2255
2256void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002257 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002258 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002259
2260 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002261}
2262
2263void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2264 VkResult result) {
2265 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002266 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2267 if (cb_state) {
2268 cb_state->Reset();
2269 }
locke-lunargd556cc32019-09-17 01:21:23 -06002270 }
2271}
2272
2273CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2274 // initially assume everything is static state
2275 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2276
2277 if (ds) {
2278 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002279 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002280 }
2281 }
locke-lunargd556cc32019-09-17 01:21:23 -06002282 return flags;
2283}
2284
2285// Validation cache:
2286// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002287
2288void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2289 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002290 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002291 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002292 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002293
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002294 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002295 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002296 const auto &create_info = pipe_state->create_info.graphics;
2297 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2298 const auto *viewport_state = create_info.pViewportState;
2299 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002300 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002301 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002302 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002303 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002304
2305 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002306 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2307 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002308 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002309 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002310 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002311 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002312 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002313 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002314
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002315 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002316 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2317 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2318 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002319 if (!has_dynamic_viewport_count) {
2320 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002321 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002322 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2323 // should become = ~uint32_t(0) if the other interpretation is correct.
2324 }
2325 }
2326 if (!has_dynamic_scissor_count) {
2327 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002328 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002329 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2330 // should become = ~uint32_t(0) if the other interpretation is correct.
2331 }
2332 }
locke-lunargd556cc32019-09-17 01:21:23 -06002333 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002334 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002335 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002336 if (!disabled[command_buffer_state]) {
2337 cb_state->AddChild(pipe_state);
2338 }
locke-lunargd556cc32019-09-17 01:21:23 -06002339}
2340
2341void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2342 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002343 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002344 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002345 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2346 cb_state->viewportMask |= bits;
2347 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002348
2349 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2350 for (size_t i = 0; i < viewportCount; ++i) {
2351 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2352 }
locke-lunargd556cc32019-09-17 01:21:23 -06002353}
2354
2355void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2356 uint32_t exclusiveScissorCount,
2357 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002358 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002359 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002360 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2361 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002362}
2363
2364void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2365 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002366 if (disabled[command_buffer_state]) return;
2367
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002368 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002369 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002370
2371 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002372 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002373 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002374 }
2375}
2376
2377void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2378 uint32_t viewportCount,
2379 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002380 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002381 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002382 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2383 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002384}
2385
2386void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2387 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2388 const VkAllocationCallbacks *pAllocator,
2389 VkAccelerationStructureNV *pAccelerationStructure,
2390 VkResult result) {
2391 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002392 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002393
2394 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002395 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002396 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002397 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002398 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2399
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002400 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002401 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002402 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002403 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2404 &as_state->build_scratch_memory_requirements);
2405
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002406 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002407 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002408 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002409 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2410 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002411 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002412 Add(std::move(as_state));
locke-lunargd556cc32019-09-17 01:21:23 -06002413}
2414
Jeff Bolz95176d02020-04-01 00:36:16 -05002415void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2416 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2417 const VkAllocationCallbacks *pAllocator,
2418 VkAccelerationStructureKHR *pAccelerationStructure,
2419 VkResult result) {
2420 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002421 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002422 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002423 Add(std::move(as_state));
Jeff Bolz95176d02020-04-01 00:36:16 -05002424}
2425
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002426void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2427 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2428 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2429 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2430 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002431 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002432 if (dst_as_state != nullptr) {
2433 dst_as_state->Build(&pInfos[i]);
2434 }
2435 }
2436}
2437
sourav parmarcd5fb182020-07-17 12:58:44 -07002438void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2439 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2440 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002441 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002442 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002443 return;
2444 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002445 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002446 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002447 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002448 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002449 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002450 if (!disabled[command_buffer_state]) {
2451 cb_state->AddChild(dst_as_state);
2452 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002453 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002454 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002455 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002456 if (src_as_state != nullptr) {
2457 cb_state->AddChild(src_as_state);
2458 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002459 }
2460 }
2461 cb_state->hasBuildAccelerationStructureCmd = true;
2462}
2463
2464void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2465 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2466 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2467 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002468 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2469 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002470 return;
2471 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002472 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002473 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002474 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002475 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002476 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002477 if (!disabled[command_buffer_state]) {
2478 cb_state->AddChild(dst_as_state);
2479 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002480 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002481 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002482 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002483 if (src_as_state != nullptr) {
2484 cb_state->AddChild(src_as_state);
2485 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002486 }
2487 }
2488 cb_state->hasBuildAccelerationStructureCmd = true;
2489}
locke-lunargd556cc32019-09-17 01:21:23 -06002490void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002491 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002492 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002493 if (as_state != nullptr) {
2494 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2495 as_state->memory_requirements = *pMemoryRequirements;
2496 as_state->memory_requirements_checked = true;
2497 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2498 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2499 as_state->build_scratch_memory_requirements_checked = true;
2500 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2501 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2502 as_state->update_scratch_memory_requirements_checked = true;
2503 }
2504 }
2505}
2506
sourav parmarcd5fb182020-07-17 12:58:44 -07002507void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2508 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002509 if (VK_SUCCESS != result) return;
2510 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002511 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002512
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002513 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002514 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002515 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002516 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002517 if (mem_state) {
2518 as_state->SetMemBinding(mem_state, info.memoryOffset);
2519 }
locke-lunargd556cc32019-09-17 01:21:23 -06002520
2521 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002522 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002523 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002524 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2525 }
2526 }
2527 }
2528}
2529
2530void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2531 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2532 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002533 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2534 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002535 return;
2536 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002537 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002538
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002539 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002540 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002541 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002542 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002543 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002544 }
locke-lunargd556cc32019-09-17 01:21:23 -06002545 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002546 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002547 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002548 if (src_as_state != nullptr) {
2549 cb_state->AddChild(src_as_state);
2550 }
locke-lunargd556cc32019-09-17 01:21:23 -06002551 }
2552 cb_state->hasBuildAccelerationStructureCmd = true;
2553}
2554
2555void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2556 VkAccelerationStructureNV dst,
2557 VkAccelerationStructureNV src,
2558 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002559 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002560 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002561 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2562 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002563 if (!disabled[command_buffer_state]) {
2564 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2565 }
locke-lunargd556cc32019-09-17 01:21:23 -06002566 if (dst_as_state != nullptr && src_as_state != nullptr) {
2567 dst_as_state->built = true;
2568 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002569 }
2570 }
2571}
2572
Jeff Bolz95176d02020-04-01 00:36:16 -05002573void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2574 VkAccelerationStructureKHR accelerationStructure,
2575 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002576 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002577}
2578
Jeff Bolz95176d02020-04-01 00:36:16 -05002579void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2580 VkAccelerationStructureNV accelerationStructure,
2581 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002582 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002583}
2584
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002585void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2586 uint32_t viewportCount,
2587 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002588 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002589 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002590}
2591
locke-lunargd556cc32019-09-17 01:21:23 -06002592void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002593 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002594 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002595}
2596
2597void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2598 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002599 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002600 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002601}
2602
2603void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2604 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002605 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002606 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002607}
2608
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002609void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2610 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002611 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002612 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002613 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2614 cb_state->scissorMask |= bits;
2615 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002616}
2617
locke-lunargd556cc32019-09-17 01:21:23 -06002618void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002619 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002620 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002621}
2622
2623void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2624 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002625 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002626 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002627}
2628
2629void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2630 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002631 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002632 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002633}
2634
2635void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2636 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002637 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002638 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002639}
2640
2641void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2642 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002643 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002644 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002645}
2646
locke-lunargd556cc32019-09-17 01:21:23 -06002647// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2648void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2649 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2650 uint32_t firstSet, uint32_t setCount,
2651 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2652 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002653 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002654 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002655 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002656 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002657
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002658 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2659 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002660}
2661
locke-lunargd556cc32019-09-17 01:21:23 -06002662void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2663 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2664 uint32_t set, uint32_t descriptorWriteCount,
2665 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002666 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002667 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002668 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002669}
2670
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002671void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2672 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2673 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002674 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2675 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002676 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002677 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2678 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002679
2680 auto &push_constant_data = cb_state->push_constant_data;
2681 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2682 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002683 cb_state->push_constant_pipeline_layout_set = layout;
2684
2685 auto flags = stageFlags;
2686 uint32_t bit_shift = 0;
2687 while (flags) {
2688 if (flags & 1) {
2689 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2690 const auto it = cb_state->push_constant_data_update.find(flag);
2691
2692 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002693 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002694 }
2695 }
2696 flags = flags >> 1;
2697 ++bit_shift;
2698 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002699 }
2700}
2701
locke-lunargd556cc32019-09-17 01:21:23 -06002702void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2703 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002704 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002705
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002706 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002707 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002708 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002709 cb_state->index_buffer_binding.offset = offset;
2710 cb_state->index_buffer_binding.index_type = indexType;
2711 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002712 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002713 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002714 }
locke-lunargd556cc32019-09-17 01:21:23 -06002715}
2716
2717void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2718 uint32_t bindingCount, const VkBuffer *pBuffers,
2719 const VkDeviceSize *pOffsets) {
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->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002722
2723 uint32_t end = firstBinding + bindingCount;
2724 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2725 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2726 }
2727
2728 for (uint32_t i = 0; i < bindingCount; ++i) {
2729 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002730 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002731 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002732 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2733 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002734 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002735 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002736 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002737 }
locke-lunargd556cc32019-09-17 01:21:23 -06002738 }
2739}
2740
2741void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2742 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002743 if (disabled[command_buffer_state]) return;
2744
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002745 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002746 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002747}
2748
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002749void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2750 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002751 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002752 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002753}
2754
2755void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2756 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002757 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002758 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2759
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002760 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2761 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002762}
2763
Tony-LunarGc43525f2021-11-15 16:12:38 -07002764void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2765 const VkDependencyInfo* pDependencyInfo) {
2766 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2767 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2768
2769 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2770 cb_state->RecordBarriers(*pDependencyInfo);
2771}
2772
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002773void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2774 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002775 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002776 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002777}
2778
2779void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2780 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002781 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002782 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002783}
2784
Tony-LunarGa2662db2021-11-16 07:26:24 -07002785void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2786 VkPipelineStageFlags2 stageMask) {
2787 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2788 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2789}
2790
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002791void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2792 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2793 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2794 uint32_t bufferMemoryBarrierCount,
2795 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2796 uint32_t imageMemoryBarrierCount,
2797 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002798 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2799 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002800 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2801 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002802}
2803
2804void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2805 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002806 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002807 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002808 const auto &dep_info = pDependencyInfos[i];
2809 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2810 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2811 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002812 }
2813}
2814
Tony-LunarG1364cf52021-11-17 16:10:11 -07002815void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2816 const VkDependencyInfo *pDependencyInfos) {
2817 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2818 for (uint32_t i = 0; i < eventCount; i++) {
2819 const auto &dep_info = pDependencyInfos[i];
2820 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2821 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2822 cb_state->RecordBarriers(dep_info);
2823 }
2824}
2825
Jeremy Gebben79649152021-06-22 14:46:24 -06002826void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2827 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2828 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2829 uint32_t bufferMemoryBarrierCount,
2830 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2831 uint32_t imageMemoryBarrierCount,
2832 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002833 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002834 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2835 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2836 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002837}
2838
2839void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2840 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002841 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002842 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2843 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002844}
2845
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002846void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2847 const VkDependencyInfo *pDependencyInfo) {
2848 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2849 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2850 cb_state->RecordBarriers(*pDependencyInfo);
2851}
2852
locke-lunargd556cc32019-09-17 01:21:23 -06002853void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2854 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002855 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002856
locke-lunargd556cc32019-09-17 01:21:23 -06002857 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002858 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002859 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002860 if (!disabled[query_validation]) {
2861 cb_state->BeginQuery(query);
2862 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002863 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002864 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002865 cb_state->AddChild(pool_state);
2866 }
locke-lunargd556cc32019-09-17 01:21:23 -06002867}
2868
2869void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002870 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002871 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002872 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002873 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002874 if (!disabled[query_validation]) {
2875 cb_state->EndQuery(query_obj);
2876 }
2877 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002878 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002879 cb_state->AddChild(pool_state);
2880 }
locke-lunargd556cc32019-09-17 01:21:23 -06002881}
2882
2883void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2884 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002885 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002886 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002887
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002888 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002889 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002890
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002891 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002892 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002893 cb_state->AddChild(pool_state);
2894 }
locke-lunargd556cc32019-09-17 01:21:23 -06002895}
2896
2897void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2898 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2899 VkDeviceSize dstOffset, VkDeviceSize stride,
2900 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002901 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2902
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002903 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002904 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002905 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002906 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002907 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002908 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002909}
2910
2911void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2912 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002913 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002914 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002915}
2916
2917void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2918 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2919 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002920 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002921 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002922}
2923
Tony-LunarGde9936b2021-11-17 15:34:11 -07002924void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
2925 VkQueryPool queryPool, uint32_t slot) {
2926 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2927 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
2928}
2929
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002930void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
2931 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
2932 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
2933 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002934 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002935 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002936 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002937 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002938 cb_state->AddChild(pool_state);
2939 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002940 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002941}
2942
locke-lunargd556cc32019-09-17 01:21:23 -06002943void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
2944 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
2945 VkResult result) {
2946 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002947
Jeremy Gebben88f58142021-06-01 10:07:52 -06002948 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002949 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002950 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002951
locke-lunargd556cc32019-09-17 01:21:23 -06002952 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002953 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002954 }
2955 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06002956
Jeremy Gebben9f537102021-10-05 16:37:12 -06002957 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06002958 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06002959}
2960
locke-lunargd556cc32019-09-17 01:21:23 -06002961void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
2962 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2963 VkResult result) {
2964 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002965 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002966}
2967
Mike Schuchardt2df08912020-12-15 16:28:09 -08002968void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002969 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2970 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002971 if (VK_SUCCESS != result) return;
2972
Jeremy Gebben082a9832021-10-28 13:40:11 -06002973 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002974}
2975
Mike Schuchardt2df08912020-12-15 16:28:09 -08002976void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002977 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2978 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002979 if (VK_SUCCESS != result) return;
2980
Jeremy Gebben082a9832021-10-28 13:40:11 -06002981 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002982}
2983
locke-lunargd556cc32019-09-17 01:21:23 -06002984void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
2985 const VkRenderPassBeginInfo *pRenderPassBegin,
2986 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002987 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002988 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002989}
2990
2991void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
2992 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002993 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002994 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002995 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002996}
2997
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002998void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2999 uint32_t counterBufferCount,
3000 const VkBuffer *pCounterBuffers,
3001 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003002 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003003
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003004 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003005 cb_state->transform_feedback_active = true;
3006}
3007
3008void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3009 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3010 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003011 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003012
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003013 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003014 cb_state->transform_feedback_active = false;
3015}
3016
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003017void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3018 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003019 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003020
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003021 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003022 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003023 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3024 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003025}
3026
3027void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003028 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003029
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003030 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003031 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003032 cb_state->conditional_rendering_inside_render_pass = false;
3033 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003034}
3035
amhagana448ea52021-11-02 14:09:14 -04003036void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003037 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003038 cb_state->activeRenderPass = nullptr;
3039}
3040
3041void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3042 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003043 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003044 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3045}
3046
Tony-LunarG40b33882021-12-02 12:40:11 -07003047void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3048 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3049 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3050}
3051
amhagana448ea52021-11-02 14:09:14 -04003052void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3053 RecordCmdEndRenderingRenderPassState(commandBuffer);
3054}
3055
Tony-LunarG40b33882021-12-02 12:40:11 -07003056void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3057 RecordCmdEndRenderingRenderPassState(commandBuffer);
3058}
3059
Tony-LunarG977448c2019-12-02 14:52:02 -07003060void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3061 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003062 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003063 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003064 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003065}
3066
locke-lunargd556cc32019-09-17 01:21:23 -06003067void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003068 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003069 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003070}
3071
3072void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003073 const VkSubpassBeginInfo *pSubpassBeginInfo,
3074 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003075 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003076 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003077}
3078
Tony-LunarG977448c2019-12-02 14:52:02 -07003079void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003080 const VkSubpassBeginInfo *pSubpassBeginInfo,
3081 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003082 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003083 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003084}
3085
3086void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003087 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003088 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003089}
3090
3091void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003092 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003093 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003094 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003095}
3096
Tony-LunarG977448c2019-12-02 14:52:02 -07003097void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003098 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003099 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003100 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003101}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003102
locke-lunargd556cc32019-09-17 01:21:23 -06003103void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3104 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003105 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003106
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003107 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003108}
3109
3110void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3111 VkFlags flags, void **ppData, VkResult result) {
3112 if (VK_SUCCESS != result) return;
3113 RecordMappedMemory(mem, offset, size, ppData);
3114}
3115
3116void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003117 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003118 if (mem_info) {
3119 mem_info->mapped_range = MemRange();
3120 mem_info->p_driver_data = nullptr;
3121 }
3122}
3123
3124void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003125 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003126 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003127 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3128 // See: VUID-vkGetImageSubresourceLayout-image-01895
3129 image_state->fragment_encoder =
3130 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003131 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003132 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003133 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003134 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003135 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003136
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003137 if (!swapchain_image.fake_base_address) {
3138 auto size = image_state->fragment_encoder->TotalSize();
3139 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003140 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003141 // All images bound to this swapchain and index are aliases
3142 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003143 }
3144 } else {
3145 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003146 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003147 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003148 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003149 }
locke-lunargd556cc32019-09-17 01:21:23 -06003150 }
locke-lunargd556cc32019-09-17 01:21:23 -06003151 }
3152}
3153
3154void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3155 VkDeviceSize memoryOffset, VkResult result) {
3156 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003157 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003158 bind_info.image = image;
3159 bind_info.memory = mem;
3160 bind_info.memoryOffset = memoryOffset;
3161 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003162}
3163
3164void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003165 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003166 if (VK_SUCCESS != result) return;
3167 for (uint32_t i = 0; i < bindInfoCount; i++) {
3168 UpdateBindImageMemoryState(pBindInfos[i]);
3169 }
3170}
3171
3172void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003173 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003174 if (VK_SUCCESS != result) return;
3175 for (uint32_t i = 0; i < bindInfoCount; i++) {
3176 UpdateBindImageMemoryState(pBindInfos[i]);
3177 }
3178}
3179
3180void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003181 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003182 if (event_state) {
3183 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3184 }
locke-lunargd556cc32019-09-17 01:21:23 -06003185}
3186
3187void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3188 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3189 VkResult result) {
3190 if (VK_SUCCESS != result) return;
3191 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3192 pImportSemaphoreFdInfo->flags);
3193}
3194
3195void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003196 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003197 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003198 if (semaphore_state) {
3199 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003200 }
3201}
3202
3203#ifdef VK_USE_PLATFORM_WIN32_KHR
3204void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3205 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3206 if (VK_SUCCESS != result) return;
3207 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3208 pImportSemaphoreWin32HandleInfo->flags);
3209}
3210
3211void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3212 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3213 HANDLE *pHandle, VkResult result) {
3214 if (VK_SUCCESS != result) return;
3215 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3216}
3217
3218void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3219 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3220 if (VK_SUCCESS != result) return;
3221 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3222 pImportFenceWin32HandleInfo->flags);
3223}
3224
3225void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3226 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3227 HANDLE *pHandle, VkResult result) {
3228 if (VK_SUCCESS != result) return;
3229 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3230}
3231#endif
3232
3233void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3234 VkResult result) {
3235 if (VK_SUCCESS != result) return;
3236 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3237}
3238
Mike Schuchardt2df08912020-12-15 16:28:09 -08003239void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3240 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003241 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003242
3243 if (fence_node) {
3244 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003245 }
3246}
3247
3248void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3249 VkResult result) {
3250 if (VK_SUCCESS != result) return;
3251 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3252}
3253
Mike Schuchardt2df08912020-12-15 16:28:09 -08003254void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003255 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003256 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003257 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003258 }
3259}
3260
3261void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3262 VkResult result) {
3263 if (VK_SUCCESS != result) return;
3264 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3265}
3266
3267void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3268 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3269 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003270 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003271}
3272
3273void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003274 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003275 SWAPCHAIN_NODE *old_swapchain_state) {
3276 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003277 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003278 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003279 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003280 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3281 surface_state->AddParent(swapchain.get());
3282 surface_state->swapchain = swapchain.get();
3283 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003284 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003285 } else {
3286 surface_state->swapchain = nullptr;
3287 }
3288 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003289 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003290 if (old_swapchain_state) {
3291 old_swapchain_state->retired = true;
3292 }
3293 return;
3294}
3295
3296void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3297 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3298 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003299 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003300 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003301 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003302}
3303
3304void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3305 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003306 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003307}
3308
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003309void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3310 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3311 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3312 VkResult result) {
3313 if (VK_SUCCESS != result) return;
3314 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003315 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003316}
3317
locke-lunargd556cc32019-09-17 01:21:23 -06003318void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003319 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003320 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3321 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003322 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003323 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003324 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003325 }
3326 }
3327
Tony-LunarG6f887e52021-07-27 11:23:14 -06003328 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003329 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3330 // 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
3331 // confused itself just as much.
3332 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3333 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3334 // Mark the image as having been released to the WSI
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003335 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003336 if (swapchain_data) {
3337 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003338 if (present_id_info) {
3339 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3340 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3341 }
3342 }
locke-lunargd556cc32019-09-17 01:21:23 -06003343 }
3344 }
locke-lunargd556cc32019-09-17 01:21:23 -06003345}
3346
3347void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3348 const VkSwapchainCreateInfoKHR *pCreateInfos,
3349 const VkAllocationCallbacks *pAllocator,
3350 VkSwapchainKHR *pSwapchains, VkResult result) {
3351 if (pCreateInfos) {
3352 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003353 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003354 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003355 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3356 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003357 }
3358 }
3359}
3360
3361void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3362 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003363 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003364 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003365 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3366 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003367 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003368 }
3369
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003370 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003371 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003372 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3373 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003374 semaphore_state->EnqueueAcquire();
locke-lunargd556cc32019-09-17 01:21:23 -06003375 }
3376
3377 // Mark the image as acquired.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003378 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003379 if (swapchain_data) {
3380 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003381 }
3382}
3383
3384void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3385 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3386 VkResult result) {
3387 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3388 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3389}
3390
3391void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3392 uint32_t *pImageIndex, VkResult result) {
3393 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3394 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3395 pAcquireInfo->fence, pImageIndex);
3396}
3397
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003398std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3399 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3400}
3401
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003402void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3403 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3404 VkResult result) {
3405 if (result != VK_SUCCESS) {
3406 return;
3407 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003408 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003409 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003410 // this can fail if the allocator fails
3411 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3412 if (result != VK_SUCCESS) {
3413 return;
3414 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003415 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003416 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3417 if (result != VK_SUCCESS) {
3418 return;
3419 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003420
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003421 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003422 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003423 }
3424}
3425
3426// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003427static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003428 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003429}
3430
3431void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3432 uint32_t *pQueueFamilyPropertyCount,
3433 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003434 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3435 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003436 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003437}
3438
3439void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003440 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003441 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3442 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003443 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003444}
3445
3446void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003447 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003448 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3449 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003450 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003451}
3452void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3453 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003454 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003455}
3456
Jeremy Gebben082a9832021-10-28 13:40:11 -06003457void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003458
3459void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3460 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3461 const VkAllocationCallbacks *pAllocator,
3462 VkSurfaceKHR *pSurface, VkResult result) {
3463 if (VK_SUCCESS != result) return;
3464 RecordVulkanSurface(pSurface);
3465}
3466
3467#ifdef VK_USE_PLATFORM_ANDROID_KHR
3468void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3469 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3470 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3471 VkResult result) {
3472 if (VK_SUCCESS != result) return;
3473 RecordVulkanSurface(pSurface);
3474}
3475#endif // VK_USE_PLATFORM_ANDROID_KHR
3476
3477#ifdef VK_USE_PLATFORM_IOS_MVK
3478void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3479 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3480 VkResult result) {
3481 if (VK_SUCCESS != result) return;
3482 RecordVulkanSurface(pSurface);
3483}
3484#endif // VK_USE_PLATFORM_IOS_MVK
3485
3486#ifdef VK_USE_PLATFORM_MACOS_MVK
3487void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3488 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3489 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3490 VkResult result) {
3491 if (VK_SUCCESS != result) return;
3492 RecordVulkanSurface(pSurface);
3493}
3494#endif // VK_USE_PLATFORM_MACOS_MVK
3495
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003496#ifdef VK_USE_PLATFORM_METAL_EXT
3497void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3498 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3499 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3500 VkResult result) {
3501 if (VK_SUCCESS != result) return;
3502 RecordVulkanSurface(pSurface);
3503}
3504#endif // VK_USE_PLATFORM_METAL_EXT
3505
locke-lunargd556cc32019-09-17 01:21:23 -06003506#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3507void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3508 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3509 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3510 VkResult result) {
3511 if (VK_SUCCESS != result) return;
3512 RecordVulkanSurface(pSurface);
3513}
3514#endif // VK_USE_PLATFORM_WAYLAND_KHR
3515
3516#ifdef VK_USE_PLATFORM_WIN32_KHR
3517void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3518 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3519 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3520 VkResult result) {
3521 if (VK_SUCCESS != result) return;
3522 RecordVulkanSurface(pSurface);
3523}
3524#endif // VK_USE_PLATFORM_WIN32_KHR
3525
3526#ifdef VK_USE_PLATFORM_XCB_KHR
3527void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3528 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3529 VkResult result) {
3530 if (VK_SUCCESS != result) return;
3531 RecordVulkanSurface(pSurface);
3532}
3533#endif // VK_USE_PLATFORM_XCB_KHR
3534
3535#ifdef VK_USE_PLATFORM_XLIB_KHR
3536void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3537 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3538 VkResult result) {
3539 if (VK_SUCCESS != result) return;
3540 RecordVulkanSurface(pSurface);
3541}
3542#endif // VK_USE_PLATFORM_XLIB_KHR
3543
Niklas Haas8b84af12020-04-19 22:20:11 +02003544void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3545 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3546 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3547 VkResult result) {
3548 if (VK_SUCCESS != result) return;
3549 RecordVulkanSurface(pSurface);
3550}
3551
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003552void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3553 VkSurfaceKHR surface,
3554 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3555 VkResult result) {
3556 if (VK_SUCCESS != result) return;
3557 auto surface_state = Get<SURFACE_STATE>(surface);
3558 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3559}
3560
3561void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3562 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3563 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3564 if (VK_SUCCESS != result) return;
3565 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3566 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3567}
3568
3569void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3570 VkSurfaceKHR surface,
3571 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3572 VkResult result) {
3573 auto surface_state = Get<SURFACE_STATE>(surface);
3574 VkSurfaceCapabilitiesKHR caps{
3575 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3576 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3577 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3578 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3579 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3580 };
3581 surface_state->SetCapabilities(physicalDevice, caps);
3582}
3583
locke-lunargd556cc32019-09-17 01:21:23 -06003584void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3585 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3586 VkBool32 *pSupported, VkResult result) {
3587 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003588 auto surface_state = Get<SURFACE_STATE>(surface);
3589 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3590}
3591
3592void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3593 VkSurfaceKHR surface,
3594 uint32_t *pPresentModeCount,
3595 VkPresentModeKHR *pPresentModes,
3596 VkResult result) {
3597 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3598
3599 if (pPresentModes) {
3600 auto surface_state = Get<SURFACE_STATE>(surface);
3601 surface_state->SetPresentModes(physicalDevice,
3602 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3603 }
3604}
3605
3606void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3607 uint32_t *pSurfaceFormatCount,
3608 VkSurfaceFormatKHR *pSurfaceFormats,
3609 VkResult result) {
3610 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3611
3612 if (pSurfaceFormats) {
3613 auto surface_state = Get<SURFACE_STATE>(surface);
3614 surface_state->SetFormats(physicalDevice,
3615 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3616 }
3617}
3618
3619void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3620 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3621 uint32_t *pSurfaceFormatCount,
3622 VkSurfaceFormat2KHR *pSurfaceFormats,
3623 VkResult result) {
3624 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3625
3626 if (pSurfaceFormats) {
3627 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3628 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3629 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3630 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3631 }
3632 surface_state->SetFormats(physicalDevice, std::move(fmts));
3633 }
locke-lunargd556cc32019-09-17 01:21:23 -06003634}
3635
locke-lunargd556cc32019-09-17 01:21:23 -06003636void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3637 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003638 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003639 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003640 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3641}
3642
3643void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003644 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003645 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003646 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3647}
3648
3649void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3650 const VkDebugUtilsLabelEXT *pLabelInfo) {
3651 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3652
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003653 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003654 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3655 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003656 cb_state->debug_label = LoggingLabel(pLabelInfo);
3657}
3658
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003659void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3660 uint32_t queueFamilyIndex,
3661 uint32_t *pCounterCount,
3662 VkPerformanceCounterKHR *pCounters) {
3663 if (NULL == pCounters) return;
3664
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003665 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3666 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003667
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003668 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3669 queue_family_counters->counters.resize(*pCounterCount);
3670 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003671
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003672 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003673}
3674
3675void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3676 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3677 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3678 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3679 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3680}
3681
3682void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3683 VkResult result) {
3684 if (result == VK_SUCCESS) performance_lock_acquired = true;
3685}
3686
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003687void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3688 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003689 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003690 cmd_buffer.second->performance_lock_released = true;
3691 }
3692}
3693
locke-lunargd556cc32019-09-17 01:21:23 -06003694void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003695 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003696 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003697 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003698}
3699
3700void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003701 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003702 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003703 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003704}
3705
Mike Schuchardt2df08912020-12-15 16:28:09 -08003706void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3707 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003708 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003709}
3710
Mike Schuchardt2df08912020-12-15 16:28:09 -08003711void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3712 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3713 const VkAllocationCallbacks *pAllocator,
3714 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3715 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003716 if (VK_SUCCESS != result) return;
3717 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3718}
3719
3720void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003721 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3722 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003723 if (VK_SUCCESS != result) return;
3724 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3725}
3726
3727void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003728 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003729 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003730 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3731 assert(template_state);
3732 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003733 // TODO: Record template push descriptor updates
3734 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003735 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003736 }
3737 }
3738}
3739
3740void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3741 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3742 const void *pData) {
3743 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3744}
3745
3746void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003747 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003748 const void *pData) {
3749 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3750}
3751
Mike Schuchardt2df08912020-12-15 16:28:09 -08003752void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3753 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3754 VkPipelineLayout layout, uint32_t set,
3755 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003756 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003757
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003758 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003759 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003760 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003761 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003762 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003763 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003764 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003765 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003766 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003767 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003768 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3769 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003770 }
3771}
3772
3773void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3774 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003775 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003776 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003777 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003778 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003779 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003780 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003781 }
3782}
3783
3784void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3785 uint32_t *pPropertyCount,
3786 VkDisplayPlanePropertiesKHR *pProperties,
3787 VkResult result) {
3788 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3789 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3790}
3791
3792void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3793 uint32_t *pPropertyCount,
3794 VkDisplayPlaneProperties2KHR *pProperties,
3795 VkResult result) {
3796 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3797 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3798}
3799
3800void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3801 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3802 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003803 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003804 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003805 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003806}
3807
3808void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3809 uint32_t query, uint32_t index) {
3810 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003811 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003812 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003813 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003814}
3815
3816void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3817 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003818 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003819
3820 if (create_info->format != VK_FORMAT_UNDEFINED) {
3821 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003822 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003823 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3824 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003825 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003826
Jeremy Gebben082a9832021-10-28 13:40:11 -06003827 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003828}
3829
3830void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3831 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3832 const VkAllocationCallbacks *pAllocator,
3833 VkSamplerYcbcrConversion *pYcbcrConversion,
3834 VkResult result) {
3835 if (VK_SUCCESS != result) return;
3836 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3837}
3838
3839void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3840 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3841 const VkAllocationCallbacks *pAllocator,
3842 VkSamplerYcbcrConversion *pYcbcrConversion,
3843 VkResult result) {
3844 if (VK_SUCCESS != result) return;
3845 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3846}
3847
3848void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3849 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003850 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003851}
3852
3853void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3854 VkSamplerYcbcrConversion ycbcrConversion,
3855 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003856 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003857}
3858
Tony-LunarG977448c2019-12-02 14:52:02 -07003859void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3860 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003861 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003862 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003863
3864 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003865 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003866 if (!query_pool_state) return;
3867
3868 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003869 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3870 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003871 auto query_index = firstQuery + i;
3872 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003873 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003874 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003875 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003876 }
3877 }
locke-lunargd556cc32019-09-17 01:21:23 -06003878 }
3879}
3880
Tony-LunarG977448c2019-12-02 14:52:02 -07003881void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3882 uint32_t queryCount) {
3883 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3884}
3885
3886void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3887 uint32_t queryCount) {
3888 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3889}
3890
locke-lunargd556cc32019-09-17 01:21:23 -06003891void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003892 const UPDATE_TEMPLATE_STATE *template_state,
3893 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003894 // Translate the templated update into a normal update for validation...
3895 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3896 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3897 decoded_update.desc_writes.data(), 0, NULL);
3898}
3899
3900// Update the common AllocateDescriptorSetsData
3901void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003902 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003903 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003904 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003905 if (layout) {
3906 ds_data->layout_nodes[i] = layout;
3907 // Count total descriptors required per type
3908 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3909 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003910 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3911 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003912 }
3913 }
3914 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3915 }
3916}
3917
locke-lunargd556cc32019-09-17 01:21:23 -06003918void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3919 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003920 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003921 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003922}
3923
Tony-LunarG745150c2021-07-02 15:07:31 -06003924void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3925 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3926 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003927 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003928 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003929}
3930
locke-lunargd556cc32019-09-17 01:21:23 -06003931void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
3932 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
3933 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003934 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003935 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003936}
3937
Tony-LunarG745150c2021-07-02 15:07:31 -06003938void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3939 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
3940 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
3941 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003942 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003943 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003944}
3945
locke-lunargd556cc32019-09-17 01:21:23 -06003946void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3947 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003948 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003949 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003950 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003951 if (!disabled[command_buffer_state]) {
3952 cb_state->AddChild(buffer_state);
3953 }
locke-lunargd556cc32019-09-17 01:21:23 -06003954}
3955
3956void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3957 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003958 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003959 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003960 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003961 if (!disabled[command_buffer_state]) {
3962 cb_state->AddChild(buffer_state);
3963 }
locke-lunargd556cc32019-09-17 01:21:23 -06003964}
3965
3966void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003967 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003968 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06003969}
3970
3971void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3972 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003973 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003974 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003975 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003976 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003977 cb_state->AddChild(buffer_state);
3978 }
locke-lunargd556cc32019-09-17 01:21:23 -06003979}
3980
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003981void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3982 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003983 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003984 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3985}
3986
3987void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3988 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003989 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003990 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3991}
3992
Tony-LunarG977448c2019-12-02 14:52:02 -07003993void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3994 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07003995 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003996 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003997 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003998 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003999 auto buffer_state = Get<BUFFER_STATE>(buffer);
4000 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004001 cb_state->AddChild(buffer_state);
4002 cb_state->AddChild(count_buffer_state);
4003 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004004}
4005
locke-lunargd556cc32019-09-17 01:21:23 -06004006void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4007 VkDeviceSize offset, VkBuffer countBuffer,
4008 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4009 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004010 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004011 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004012}
4013
4014void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4015 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4016 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004017 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004018 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004019}
4020
4021void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4022 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004023 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004024 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004025 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004026 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004027 auto buffer_state = Get<BUFFER_STATE>(buffer);
4028 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004029 cb_state->AddChild(buffer_state);
4030 cb_state->AddChild(count_buffer_state);
4031 }
locke-lunargd556cc32019-09-17 01:21:23 -06004032}
4033
4034void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4035 VkDeviceSize offset, VkBuffer countBuffer,
4036 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4037 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004038 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004039 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004040}
4041
4042void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4043 VkDeviceSize offset, VkBuffer countBuffer,
4044 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4045 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004046 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004047 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004048}
4049
4050void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4051 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004052 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004053 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004054}
4055
4056void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4057 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004058 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004059 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004060 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004061 if (!disabled[command_buffer_state] && buffer_state) {
4062 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004063 }
4064}
4065
4066void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4067 VkDeviceSize offset, VkBuffer countBuffer,
4068 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4069 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004070 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004071 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004072 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004073 auto buffer_state = Get<BUFFER_STATE>(buffer);
4074 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004075 if (buffer_state) {
4076 cb_state->AddChild(buffer_state);
4077 }
4078 if (count_buffer_state) {
4079 cb_state->AddChild(count_buffer_state);
4080 }
locke-lunargd556cc32019-09-17 01:21:23 -06004081 }
4082}
4083
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004084void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4085 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4086 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4087 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4088 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4089 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4090 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004091 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004092 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004093 cb_state->hasTraceRaysCmd = true;
4094}
4095
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004096void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4097 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4098 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4099 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4100 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4101 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004102 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004103 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004104 cb_state->hasTraceRaysCmd = true;
4105}
4106
4107void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4108 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4109 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4110 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4111 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4112 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004113 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004114 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004115 cb_state->hasTraceRaysCmd = true;
4116}
4117
locke-lunargd556cc32019-09-17 01:21:23 -06004118void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4119 const VkAllocationCallbacks *pAllocator,
4120 VkShaderModule *pShaderModule, VkResult result,
4121 void *csm_state_data) {
4122 if (VK_SUCCESS != result) return;
4123 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4124
sfricke-samsung45996a42021-09-16 13:45:27 -07004125 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004126 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004127 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4128 csm_state->unique_shader_id)
4129 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004130 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004131}
4132
John Zulauf22b0fbe2019-10-15 06:26:16 -06004133void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4134 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4135 VkResult result) {
4136 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004137 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004138
4139 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4140
4141 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004142 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004143 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004144 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004145
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004146 auto format_features = GetImageFormatFeatures(
4147 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4148 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004149
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06004150 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004151 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004152 if (!swapchain_image.fake_base_address) {
4153 auto size = image_state->fragment_encoder->TotalSize();
4154 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004155 }
4156
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004157 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004158 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004159 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004160 }
4161 }
4162
4163 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004164 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4165 }
4166}
sourav parmar35e7a002020-06-09 17:58:44 -07004167
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004168void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4169 const VkCopyAccelerationStructureInfoKHR *pInfo,
4170 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004171 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4172 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004173 if (dst_as_state != nullptr && src_as_state != nullptr) {
4174 dst_as_state->built = true;
4175 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4176 }
4177}
4178
sourav parmar35e7a002020-06-09 17:58:44 -07004179void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4180 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004181 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004182 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004183 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004184 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4185 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004186 if (dst_as_state != nullptr && src_as_state != nullptr) {
4187 dst_as_state->built = true;
4188 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004189 if (!disabled[command_buffer_state]) {
4190 cb_state->AddChild(dst_as_state);
4191 cb_state->AddChild(src_as_state);
4192 }
sourav parmar35e7a002020-06-09 17:58:44 -07004193 }
4194 }
4195}
Piers Daniell39842ee2020-07-10 16:42:33 -06004196
4197void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004198 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004199 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004200}
4201
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004202void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4203 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4204 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4205}
4206
Piers Daniell39842ee2020-07-10 16:42:33 -06004207void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004208 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004209 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004210}
4211
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004212void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4213 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4214 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4215}
4216
Piers Daniell39842ee2020-07-10 16:42:33 -06004217void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4218 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004219 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004220 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004221 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004222}
4223
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004224void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4225 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004226 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004227 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4228 cb_state->primitiveTopology = primitiveTopology;
4229}
4230
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004231void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4232 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004233 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4234 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004235 uint32_t bits = (1u << viewportCount) - 1u;
4236 cb_state->viewportWithCountMask |= bits;
4237 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004238 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004239 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004240
4241 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4242 for (size_t i = 0; i < viewportCount; ++i) {
4243 cb_state->dynamicViewports[i] = pViewports[i];
4244 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004245}
4246
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004247void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4248 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004249 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004250}
4251
4252void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004253 const VkViewport *pViewports) {
4254 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004255}
4256
4257void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4258 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004259 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004260 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004261 uint32_t bits = (1u << scissorCount) - 1u;
4262 cb_state->scissorWithCountMask |= bits;
4263 cb_state->trashedScissorMask &= ~bits;
4264 cb_state->scissorWithCountCount = scissorCount;
4265 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004266}
4267
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004268void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4269 const VkRect2D *pScissors) {
4270 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4271}
4272
4273void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4274 const VkRect2D *pScissors) {
4275 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4276}
4277
4278void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4279 uint32_t bindingCount, const VkBuffer *pBuffers,
4280 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4281 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004282 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004283 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004284
4285 uint32_t end = firstBinding + bindingCount;
4286 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4287 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4288 }
4289
4290 for (uint32_t i = 0; i < bindingCount; ++i) {
4291 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004292 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004293 vertex_buffer_binding.offset = pOffsets[i];
4294 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4295 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4296 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004297 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004298 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004299 }
4300 }
4301}
4302
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004303void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4304 uint32_t bindingCount, const VkBuffer *pBuffers,
4305 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4306 const VkDeviceSize *pStrides) {
4307 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4308 CMD_BINDVERTEXBUFFERS2EXT);
4309}
4310
4311void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4312 uint32_t bindingCount, const VkBuffer *pBuffers,
4313 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4314 const VkDeviceSize *pStrides) {
4315 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4316 CMD_BINDVERTEXBUFFERS2);
4317}
4318
Piers Daniell39842ee2020-07-10 16:42:33 -06004319void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004320 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004321 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004322}
4323
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004324void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4325 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4326 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4327}
4328
Piers Daniell39842ee2020-07-10 16:42:33 -06004329void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004330 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004331 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004332}
4333
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004334void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4335 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4336 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4337}
4338
Piers Daniell39842ee2020-07-10 16:42:33 -06004339void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004340 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004341 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004342}
4343
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004344void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4345 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4346 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4347}
4348
Piers Daniell39842ee2020-07-10 16:42:33 -06004349void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4350 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004351 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004352 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004353}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004354
4355void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4356 VkBool32 depthBoundsTestEnable) {
4357 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4358 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4359}
4360
Piers Daniell39842ee2020-07-10 16:42:33 -06004361void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004362 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004363 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004364}
4365
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004366void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4367 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4368 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4369}
4370
Piers Daniell39842ee2020-07-10 16:42:33 -06004371void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4372 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4373 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004374 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004375 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004376}
locke-lunarg4189aa22020-10-21 00:23:48 -06004377
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004378void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4379 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4380 VkCompareOp compareOp) {
4381 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4382 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4383}
4384
locke-lunarg4189aa22020-10-21 00:23:48 -06004385void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4386 uint32_t discardRectangleCount,
4387 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004388 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004389 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004390}
4391
4392void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4393 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004394 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004395 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004396}
4397
4398void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4399 VkCoarseSampleOrderTypeNV sampleOrderType,
4400 uint32_t customSampleOrderCount,
4401 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004402 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004403 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004404}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004405
4406void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004407 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004408 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004409}
4410
4411void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004412 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004413 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004414}
4415
4416void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4417 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004418 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004419 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004420}
4421
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004422void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4423 VkBool32 rasterizerDiscardEnable) {
4424 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4425 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4426}
4427
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004428void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004429 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004430 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004431}
4432
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004433void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4434 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4435 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4436}
4437
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004438void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4439 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004440 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004441 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004442}
Piers Daniell924cd832021-05-18 13:48:47 -06004443
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004444void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4445 VkBool32 primitiveRestartEnable) {
4446 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4447 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4448}
4449
Piers Daniell924cd832021-05-18 13:48:47 -06004450void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4451 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4452 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4453 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004454 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004455 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4456
4457 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4458 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4459 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004460 if (pipeline_state->create_info.graphics.pDynamicState) {
4461 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4462 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004463 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4464 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4465 break;
4466 }
4467 }
4468 }
4469 }
4470 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004471}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004472
4473void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004474 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004475 if (buffer_state) {
4476 // address is used for GPU-AV and ray tracing buffer validation
4477 buffer_state->deviceAddress = address;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06004478 buffer_address_map_.insert(address, buffer_state.get());
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004479 }
4480}
4481
4482void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4483 VkDeviceAddress address) {
4484 RecordGetBufferDeviceAddress(pInfo, address);
4485}
4486
4487void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4488 VkDeviceAddress address) {
4489 RecordGetBufferDeviceAddress(pInfo, address);
4490}
4491
4492void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4493 VkDeviceAddress address) {
4494 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004495}
4496
4497std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4498 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004499 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004500}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004501
4502std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4503 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004504 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004505 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4506}