blob: 3b637adcf9a1399f8bc11e04483d2c4313d225de [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);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700337 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
James Rumble2f6e7bb2021-07-13 15:21:20 +0100338 // 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
Agarwal, Arpit78509112022-02-17 15:29:05 -0700999 const auto *fragment_density_map_offset_features =
1000 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1001 if (fragment_density_map_offset_features) {
1002 state_tracker->enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
1003 }
1004
sfricke-samsung828e59d2021-08-22 23:20:49 -07001005 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1006 if (astc_decode_features) {
1007 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
1008 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001009
sfricke-samsung828e59d2021-08-22 23:20:49 -07001010 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1011 if (custom_border_color_features) {
1012 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
1013 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001014
sfricke-samsung828e59d2021-08-22 23:20:49 -07001015 const auto *fragment_shading_rate_features =
1016 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1017 if (fragment_shading_rate_features) {
1018 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
1019 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001020
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 const auto *extended_dynamic_state_features =
1022 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1023 if (extended_dynamic_state_features) {
1024 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
1025 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001026
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 const auto *extended_dynamic_state2_features =
1028 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1029 if (extended_dynamic_state2_features) {
1030 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
1031 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001032
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1034 if (multiview_features) {
1035 state_tracker->enabled_features.multiview_features = *multiview_features;
1036 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001037
sfricke-samsung828e59d2021-08-22 23:20:49 -07001038 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1039 if (portability_features) {
1040 state_tracker->enabled_features.portability_subset_features = *portability_features;
1041 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001042
sfricke-samsung828e59d2021-08-22 23:20:49 -07001043 const auto *shader_integer_functions2_features =
1044 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1045 if (shader_integer_functions2_features) {
1046 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1047 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001048
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1050 if (shader_sm_builtins_features) {
1051 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
1052 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001053
sfricke-samsung828e59d2021-08-22 23:20:49 -07001054 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1055 if (shader_atomic_float_features) {
1056 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
1057 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001058
sfricke-samsung828e59d2021-08-22 23:20:49 -07001059 const auto *shader_image_atomic_int64_features =
1060 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1061 if (shader_image_atomic_int64_features) {
1062 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1063 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001064
sfricke-samsung828e59d2021-08-22 23:20:49 -07001065 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1066 if (shader_clock_features) {
1067 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1068 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001069
sfricke-samsung828e59d2021-08-22 23:20:49 -07001070 const auto *conditional_rendering_features =
1071 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1072 if (conditional_rendering_features) {
1073 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1074 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001075
sfricke-samsung828e59d2021-08-22 23:20:49 -07001076 const auto *workgroup_memory_explicit_layout_features =
1077 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1078 if (workgroup_memory_explicit_layout_features) {
1079 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1080 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001081
sfricke-samsung828e59d2021-08-22 23:20:49 -07001082 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1083 if (provoking_vertex_features) {
1084 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1085 }
Locke Linf3873542021-04-26 11:25:10 -06001086
sfricke-samsung828e59d2021-08-22 23:20:49 -07001087 const auto *vertex_input_dynamic_state_features =
1088 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1089 if (vertex_input_dynamic_state_features) {
1090 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1091 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001092
sfricke-samsung828e59d2021-08-22 23:20:49 -07001093 const auto *inherited_viewport_scissor_features =
1094 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1095 if (inherited_viewport_scissor_features) {
1096 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1097 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001098
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1100 if (multi_draw_features) {
1101 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1102 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001103
sfricke-samsung828e59d2021-08-22 23:20:49 -07001104 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1105 if (color_write_features) {
1106 state_tracker->enabled_features.color_write_features = *color_write_features;
1107 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001108
sfricke-samsung828e59d2021-08-22 23:20:49 -07001109 const auto *shader_atomic_float2_features =
1110 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1111 if (shader_atomic_float2_features) {
1112 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1113 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001114
sfricke-samsung828e59d2021-08-22 23:20:49 -07001115 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1116 if (present_id_features) {
1117 state_tracker->enabled_features.present_id_features = *present_id_features;
1118 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001119
sfricke-samsung828e59d2021-08-22 23:20:49 -07001120 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1121 if (present_wait_features) {
1122 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1123 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001124
1125 const auto *ray_tracing_motion_blur_features =
1126 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1127 if (ray_tracing_motion_blur_features) {
1128 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1129 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001130
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001131 const auto *primitive_topology_list_restart_features =
1132 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1133 if (primitive_topology_list_restart_features) {
1134 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1135 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001136
ziga-lunarge1988962021-09-16 13:32:34 +02001137 const auto *zero_initialize_work_group_memory_features =
1138 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1139 if (zero_initialize_work_group_memory_features) {
1140 state_tracker->enabled_features.zero_initialize_work_group_memory_features =
1141 *zero_initialize_work_group_memory_features;
1142 }
1143
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001144 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1145 if (rgba10x6_formats_features) {
1146 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
1147 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001148
Tony-LunarG69604c42021-11-22 16:00:12 -07001149 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1150 if (image_view_min_lod_features) {
1151 state_tracker->enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
1152 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001153 }
1154
locke-lunargd556cc32019-09-17 01:21:23 -06001155 // Store physical device properties and physical device mem limits into CoreChecks structs
1156 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1157 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1158
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001159 {
1160 uint32_t n_props = 0;
1161 std::vector<VkExtensionProperties> props;
1162 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, NULL);
1163 props.resize(n_props);
Tony-LunarG8c380b92022-01-12 13:44:04 -07001164 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001165
1166 for (const auto &ext_prop : props) {
1167 state_tracker->phys_dev_extensions.insert(ext_prop.extensionName);
1168 }
1169
1170 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1171 // a path to grab that information from the physical device. This
1172 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1173 // Vulkan 1.1 (which made this core).
1174 state_tracker->has_format_feature2 =
1175 (state_tracker->api_version >= VK_API_VERSION_1_1 ||
1176 IsExtEnabled(state_tracker->instance_extensions.vk_khr_get_physical_device_properties2)) &&
1177 state_tracker->phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) !=
1178 state_tracker->phys_dev_extensions.end();
1179 }
1180
locke-lunargd556cc32019-09-17 01:21:23 -06001181 const auto &dev_ext = state_tracker->device_extensions;
1182 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1183
Tony-LunarG273f32f2021-09-28 08:56:30 -06001184 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1185 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
sfricke-samsung45996a42021-09-16 13:45:27 -07001186 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
1187 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001188 if (dev_ext.vk_feature_version_1_3)
1189 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_3, &state_tracker->phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001190 } else {
1191 // VkPhysicalDeviceVulkan11Properties
1192 //
1193 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1194
1195 if (dev_ext.vk_khr_multiview) {
1196 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1197 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1198 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1199 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1200 }
1201
1202 if (dev_ext.vk_khr_maintenance3) {
1203 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1204 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1205 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1206 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1207 }
1208
1209 // Some 1.1 properties were added to core without previous extensions
1210 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1211 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1212 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1213 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1214 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1215
1216 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1217 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1218 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1219 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1220
1221 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1222 }
1223
1224 // VkPhysicalDeviceVulkan12Properties
1225 //
1226 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1227
1228 if (dev_ext.vk_ext_descriptor_indexing) {
1229 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1230 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1231 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1232 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1233 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1234 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1235 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1236 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1237 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1238 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1239 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1240 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1241 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1242 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1243 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1244 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1245 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1246 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1247 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1248 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1249 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1250 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1251 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1252 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1253 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1254 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1255 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1256 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1257 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1258 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1259 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1260 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1261 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1262 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1263 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1264 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1265 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1266 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1267 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1268 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1269 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1270 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1271 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1272 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1273 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1274 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1275 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1276 }
1277
1278 if (dev_ext.vk_khr_depth_stencil_resolve) {
1279 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1280 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1281 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1282 depth_stencil_resolve_props.supportedDepthResolveModes;
1283 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1284 depth_stencil_resolve_props.supportedStencilResolveModes;
1285 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1286 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1287 }
1288
1289 if (dev_ext.vk_khr_timeline_semaphore) {
1290 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1291 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1292 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1293 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1294 }
1295
1296 if (dev_ext.vk_ext_sampler_filter_minmax) {
1297 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1298 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1299 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1300 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1301 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1302 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1303 }
1304
1305 if (dev_ext.vk_khr_shader_float_controls) {
1306 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1307 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1308 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1309 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1310 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1311 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1312 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1313 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1314 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1315 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1316 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1317 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1318 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1319 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1320 float_controls_props.shaderDenormFlushToZeroFloat16;
1321 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1322 float_controls_props.shaderDenormFlushToZeroFloat32;
1323 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1324 float_controls_props.shaderDenormFlushToZeroFloat64;
1325 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1326 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1327 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1328 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1329 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1330 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1331 }
locke-lunargd556cc32019-09-17 01:21:23 -06001332 }
1333
sfricke-samsung828e59d2021-08-22 23:20:49 -07001334 // Extensions with properties to extract to DeviceExtensionProperties
1335 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001336 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1337 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1338 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1339 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001340 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001341 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001342 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1343 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001344 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1345 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001346 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Agarwal, Arpit78509112022-02-17 15:29:05 -07001347 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_qcom_fragment_density_map_offset,
1348 &phys_dev_props->fragment_density_map_offset_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001349 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001350 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001351 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001352 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001353 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001354 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001355 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001356 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001357 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001358 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001359 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001360 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001361
sfricke-samsung45996a42021-09-16 13:45:27 -07001362 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001363 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001364 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1365 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001366 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1367 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1368
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001369 uint32_t num_cooperative_matrix_properties = 0;
1370 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1371 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001372 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001373
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001374 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001375 state_tracker->cooperative_matrix_properties.data());
1376 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001377
locke-lunargd556cc32019-09-17 01:21:23 -06001378 // Store queue family data
1379 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1380 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001381 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001382 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1383 state_tracker->device_queue_info_list.push_back(
1384 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001385 }
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001386 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1387 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1388 VkQueue queue = VK_NULL_HANDLE;
1389 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1390 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1391 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1392 get_info.flags = queue_info.flags;
1393 get_info.queueFamilyIndex = queue_info.queue_family_index;
1394 get_info.queueIndex = i;
1395 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1396 } else {
1397 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1398 }
1399 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001400 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001401 }
locke-lunargd556cc32019-09-17 01:21:23 -06001402 }
1403 }
1404}
1405
1406void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1407 if (!device) return;
1408
Jeremy Gebbend177d922021-10-28 13:42:10 -06001409 command_pool_map_.clear();
1410 assert(command_buffer_map_.empty());
1411 pipeline_map_.clear();
1412 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001413
1414 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001415 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001416 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001417 assert(descriptor_set_map_.empty());
1418 desc_template_map_.clear();
1419 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001420 // Because swapchains are associated with Surfaces, which are at instance level,
1421 // they need to be explicitly destroyed here to avoid continued references to
1422 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001423 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001424 entry.second->Destroy();
1425 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001426 swapchain_map_.clear();
1427 image_view_map_.clear();
1428 image_map_.clear();
1429 buffer_view_map_.clear();
1430 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001431 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001432 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001433}
1434
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001435void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1436 VkFence fence, VkResult result) {
1437 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001438 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001439
Jeremy Gebben57642982021-09-14 14:14:55 -06001440 uint64_t early_retire_seq = 0;
1441
1442 if (submitCount == 0) {
1443 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001444 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001445 early_retire_seq = queue_state->Submit(std::move(submission));
1446 }
locke-lunargd556cc32019-09-17 01:21:23 -06001447
1448 // Now process each individual submit
1449 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001450 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001451 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001452 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001453 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001454 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001455 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1456 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1457 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1458 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001459 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001460 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001461
locke-lunargd556cc32019-09-17 01:21:23 -06001462 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001463 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001464 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1465 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1466 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1467 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001468 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001469 }
1470
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001471 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001472 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001473
locke-lunargd556cc32019-09-17 01:21:23 -06001474 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001475 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001476 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001477 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001478 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001479 }
1480 auto submit_seq = queue_state->Submit(std::move(submission));
1481 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001482 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001483
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001484 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001485 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001486 }
1487}
1488
Tony-LunarG26fe2842021-11-16 14:07:59 -07001489void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1490 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001491 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001492 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001493 uint64_t early_retire_seq = 0;
1494 if (submitCount == 0) {
1495 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001496 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001497 early_retire_seq = queue_state->Submit(std::move(submission));
1498 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001499
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001500 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1501 CB_SUBMISSION submission;
1502 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001503 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1504 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001505 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001506 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001507 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1508 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001509 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001510 }
1511 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1512 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1513
1514 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001515 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001516 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001517 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001518 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001519 }
1520 auto submit_seq = queue_state->Submit(std::move(submission));
1521 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001522 }
locke-lunargd556cc32019-09-17 01:21:23 -06001523 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001524 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001525 }
1526}
1527
Tony-LunarG26fe2842021-11-16 14:07:59 -07001528void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1529 VkFence fence, VkResult result) {
1530 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1531}
1532
1533void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1534 VkFence fence, VkResult result) {
1535 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1536}
1537
locke-lunargd556cc32019-09-17 01:21:23 -06001538void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1539 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1540 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001541 if (VK_SUCCESS != result) {
1542 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001543 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001544 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1545 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1546 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1547
1548 layer_data::optional<DedicatedBinding> dedicated_binding;
1549
1550 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1551 if (dedicated) {
1552 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001553 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001554 assert(buffer_state);
1555 if (!buffer_state) {
1556 return;
1557 }
1558 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1559 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001560 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001561 assert(image_state);
1562 if (!image_state) {
1563 return;
1564 }
1565 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1566 }
1567 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001568 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1569 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001570 return;
1571}
1572
1573void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001574 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001575 if (mem_info) {
1576 fake_memory.Free(mem_info->fake_base_address);
1577 }
1578 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001579}
1580
1581void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1582 VkFence fence, VkResult result) {
1583 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001584 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001585
Jeremy Gebben57642982021-09-14 14:14:55 -06001586 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001587
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001588 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1589 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001590 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001591 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1592 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1593 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001594 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001595 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001596 if (buffer_state && mem_state) {
1597 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1598 }
locke-lunargd556cc32019-09-17 01:21:23 -06001599 }
1600 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001601 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1602 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1603 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001604 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001605 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001606 if (image_state && mem_state) {
1607 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1608 }
locke-lunargd556cc32019-09-17 01:21:23 -06001609 }
1610 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001611 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1612 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1613 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001614 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1615 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001616 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001617 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001618 if (image_state && mem_state) {
1619 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1620 }
locke-lunargd556cc32019-09-17 01:21:23 -06001621 }
1622 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001623 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001624 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001625 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001626 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001627 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001628 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001629 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001630 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001631 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001632 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001633 auto submit_seq = queue_state->Submit(std::move(submission));
1634 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001635 }
1636
1637 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001638 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001639 }
1640}
1641
1642void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1643 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1644 VkResult result) {
1645 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001646 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001647}
1648
Mike Schuchardt2df08912020-12-15 16:28:09 -08001649void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1650 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001651 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1652 if (semaphore_state) {
1653 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001654 }
1655}
1656
Mike Schuchardt2df08912020-12-15 16:28:09 -08001657void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001658 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001659 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001660 if (semaphore_state) {
1661 semaphore_state->RetireTimeline(pSignalInfo->value);
1662 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001663}
1664
locke-lunargd556cc32019-09-17 01:21:23 -06001665void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001666 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001667 if (mem_info) {
1668 mem_info->mapped_range.offset = offset;
1669 mem_info->mapped_range.size = size;
1670 mem_info->p_driver_data = *ppData;
1671 }
1672}
1673
locke-lunargd556cc32019-09-17 01:21:23 -06001674void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1675 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1676 if (VK_SUCCESS != result) return;
1677
1678 // When we know that all fences are complete we can clean/remove their CBs
1679 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1680 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001681 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001682 if (fence_state) {
1683 fence_state->Retire();
1684 }
locke-lunargd556cc32019-09-17 01:21:23 -06001685 }
1686 }
1687 // NOTE : Alternate case not handled here is when some fences have completed. In
1688 // this case for app to guarantee which fences completed it will have to call
1689 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1690}
1691
John Zulauff89de662020-04-13 18:57:34 -06001692void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1693 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001694 if (VK_SUCCESS != result) return;
1695
Jeremy Gebben15332642021-12-15 19:33:15 -07001696 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1697 // the application calls vkGetSemaphoreCounterValue() on each of them.
1698 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1699 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1700 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1701 if (semaphore_state) {
1702 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1703 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001704 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001705 }
1706}
1707
John Zulauff89de662020-04-13 18:57:34 -06001708void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1709 VkResult result) {
1710 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1711}
1712
1713void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1714 uint64_t timeout, VkResult result) {
1715 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1716}
1717
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001718void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1719 VkResult result) {
1720 if (VK_SUCCESS != result) return;
1721
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001722 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001723 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001724 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001725 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001726}
1727
1728void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1729 VkResult result) {
1730 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1731}
1732void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1733 VkResult result) {
1734 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1735}
1736
locke-lunargd556cc32019-09-17 01:21:23 -06001737void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1738 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001739 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001740 if (fence_state) {
1741 fence_state->Retire();
1742 }
locke-lunargd556cc32019-09-17 01:21:23 -06001743}
1744
Yilong Lice03a312022-01-02 02:08:35 -08001745void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1746 if (Get<QUEUE_STATE>(queue) == nullptr) {
1747 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1748 }
1749}
1750
1751void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1752 VkQueue *pQueue) {
1753 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1754}
1755
1756void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1757 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1758}
1759
locke-lunargd556cc32019-09-17 01:21:23 -06001760void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1761 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001762 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001763 if (queue_state) {
1764 queue_state->Retire();
1765 }
locke-lunargd556cc32019-09-17 01:21:23 -06001766}
1767
1768void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1769 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001770 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001771 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001772 }
1773}
1774
1775void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001776 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001777}
1778
1779void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1780 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001781 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001782}
1783
1784void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001785 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001786}
1787
1788void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1789 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001790 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001791}
1792
locke-lunargd556cc32019-09-17 01:21:23 -06001793void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001794 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001795 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001796 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001797 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001798 if (mem_state) {
1799 buffer_state->SetMemBinding(mem_state, memoryOffset);
1800 }
locke-lunargd556cc32019-09-17 01:21:23 -06001801 }
1802}
1803
1804void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1805 VkDeviceSize memoryOffset, VkResult result) {
1806 if (VK_SUCCESS != result) return;
1807 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1808}
1809
1810void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001811 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001812 for (uint32_t i = 0; i < bindInfoCount; i++) {
1813 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1814 }
1815}
1816
1817void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001818 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001819 for (uint32_t i = 0; i < bindInfoCount; i++) {
1820 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1821 }
1822}
1823
Spencer Fricke6c127102020-04-16 06:25:20 -07001824void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001825 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001826 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001827 buffer_state->memory_requirements_checked = true;
1828 }
1829}
1830
1831void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1832 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001833 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001834}
1835
1836void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001837 const VkBufferMemoryRequirementsInfo2 *pInfo,
1838 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001839 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001840}
1841
1842void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001843 const VkBufferMemoryRequirementsInfo2 *pInfo,
1844 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001845 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001846}
1847
Spencer Fricke6c127102020-04-16 06:25:20 -07001848void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001849 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001850 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001851 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001852 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001853 if (plane_info != nullptr) {
1854 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001855 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001856 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001857 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001858 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001859 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001860 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001861 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001862 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001863 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001864 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001865 }
locke-lunargd556cc32019-09-17 01:21:23 -06001866 }
1867}
1868
1869void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1870 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001871 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001872}
1873
1874void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1875 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001876 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001877}
1878
1879void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1880 const VkImageMemoryRequirementsInfo2 *pInfo,
1881 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001882 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001883}
1884
locke-lunargd556cc32019-09-17 01:21:23 -06001885void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1886 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1887 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001888 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001889 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001890}
1891
1892void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001893 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1894 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001895 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001896 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001897}
1898
1899void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001900 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1901 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001902 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001903 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001904}
1905
1906void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1907 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001908 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001909}
1910
1911void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1912 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001913 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001914}
1915
1916void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1917 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001918 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001919}
1920
1921void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1922 const VkAllocationCallbacks *pAllocator) {
1923 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001924 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001925 // Any bound cmd buffers are now invalid
1926 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001927 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1928 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1929 custom_border_color_sampler_count--;
1930 }
locke-lunargd556cc32019-09-17 01:21:23 -06001931 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001932 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001933}
1934
1935void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1936 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001937 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001938}
1939
1940void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1941 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001942 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001943}
1944
locke-lunargd556cc32019-09-17 01:21:23 -06001945void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1946 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001947 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1948 if (pool) {
1949 pool->Free(commandBufferCount, pCommandBuffers);
1950 }
locke-lunargd556cc32019-09-17 01:21:23 -06001951}
1952
1953void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1954 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1955 VkResult result) {
1956 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001957 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001958 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001959}
1960
1961void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1962 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1963 VkResult result) {
1964 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001965
1966 uint32_t index_count = 0, n_perf_pass = 0;
1967 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001968 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001969 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001970 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001971
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001972 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001973 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1974 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1975 switch (counter.scope) {
1976 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001977 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001978 break;
1979 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001980 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001981 break;
1982 default:
1983 break;
1984 }
1985 }
1986
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001987 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001988 }
1989
Jeremy Gebben082a9832021-10-28 13:40:11 -06001990 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 -06001991
locke-lunargd556cc32019-09-17 01:21:23 -06001992}
1993
1994void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1995 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001996 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001997}
1998
1999void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2000 VkCommandPoolResetFlags flags, VkResult result) {
2001 if (VK_SUCCESS != result) return;
2002 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002003 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2004 if (pool) {
2005 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002006 }
2007}
2008
2009void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2010 VkResult result) {
2011 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002012 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002013 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002014 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002015 }
2016 }
2017}
2018
locke-lunargd556cc32019-09-17 01:21:23 -06002019void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2020 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002021 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002022}
2023
2024void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2025 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002026 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002027}
2028
2029void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2030 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2031 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002032 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002033}
2034
2035bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2036 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2037 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002038 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002039 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2040 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2041 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2042 cgpl_state->pipe_state.reserve(count);
2043 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002044 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002045 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
2046 Get<RENDER_PASS_STATE>(pCreateInfos[i].renderPass),
2047 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Tony-LunarG273f32f2021-09-28 08:56:30 -06002048 } else if (enabled_features.core13.dynamicRendering) {
Tony-LunarG40b33882021-12-02 12:40:11 -07002049 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(pCreateInfos[i].pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002050 cgpl_state->pipe_state.push_back(
2051 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], std::make_shared<RENDER_PASS_STATE>(dynamic_rendering),
Jeremy Gebben9f537102021-10-05 16:37:12 -06002052 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002053 }
locke-lunargd556cc32019-09-17 01:21:23 -06002054 }
2055 return false;
2056}
2057
2058void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2059 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2060 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2061 VkResult result, void *cgpl_state_data) {
2062 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2063 // This API may create pipelines regardless of the return value
2064 for (uint32_t i = 0; i < count; i++) {
2065 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002066 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002067 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002068 }
2069 }
2070 cgpl_state->pipe_state.clear();
2071}
2072
2073bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2074 const VkComputePipelineCreateInfo *pCreateInfos,
2075 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002076 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002077 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2078 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2079 ccpl_state->pipe_state.reserve(count);
2080 for (uint32_t i = 0; i < count; i++) {
2081 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002082 ccpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002083 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002084 }
2085 return false;
2086}
2087
2088void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2089 const VkComputePipelineCreateInfo *pCreateInfos,
2090 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2091 VkResult result, void *ccpl_state_data) {
2092 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2093
2094 // This API may create pipelines regardless of the return value
2095 for (uint32_t i = 0; i < count; i++) {
2096 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002097 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002098 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002099 }
2100 }
2101 ccpl_state->pipe_state.clear();
2102}
2103
2104bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2105 uint32_t count,
2106 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2107 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002108 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002109 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2110 crtpl_state->pipe_state.reserve(count);
2111 for (uint32_t i = 0; i < count; i++) {
2112 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002113 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002114 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002115 }
2116 return false;
2117}
2118
2119void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2120 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2121 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2122 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2123 // This API may create pipelines regardless of the return value
2124 for (uint32_t i = 0; i < count; i++) {
2125 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002126 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002127 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002128 }
2129 }
2130 crtpl_state->pipe_state.clear();
2131}
2132
sourav parmarcd5fb182020-07-17 12:58:44 -07002133bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2134 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002135 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2136 const VkAllocationCallbacks *pAllocator,
2137 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002138 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002139 crtpl_state->pipe_state.reserve(count);
2140 for (uint32_t i = 0; i < count; i++) {
2141 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002142 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002143 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002144 }
2145 return false;
2146}
2147
sourav parmarcd5fb182020-07-17 12:58:44 -07002148void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2149 VkPipelineCache pipelineCache, uint32_t count,
2150 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2151 const VkAllocationCallbacks *pAllocator,
2152 VkPipeline *pPipelines, VkResult result,
2153 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002154 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2155 // This API may create pipelines regardless of the return value
2156 for (uint32_t i = 0; i < count; i++) {
2157 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002158 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002159 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002160 }
2161 }
2162 crtpl_state->pipe_state.clear();
2163}
2164
locke-lunargd556cc32019-09-17 01:21:23 -06002165void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2166 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2167 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002168 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002169 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2170 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002171 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002172 }
locke-lunargd556cc32019-09-17 01:21:23 -06002173}
2174
2175void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2176 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2177 const VkAllocationCallbacks *pAllocator,
2178 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2179 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002180 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002181}
2182
locke-lunargd556cc32019-09-17 01:21:23 -06002183void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2184 const VkAllocationCallbacks *pAllocator,
2185 VkPipelineLayout *pPipelineLayout, VkResult result) {
2186 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002187 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002188}
2189
2190void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2191 const VkAllocationCallbacks *pAllocator,
2192 VkDescriptorPool *pDescriptorPool, VkResult result) {
2193 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002194 Add(std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002195}
2196
2197void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2198 VkDescriptorPoolResetFlags flags, VkResult result) {
2199 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002200 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2201 if (pool) {
2202 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002203 }
locke-lunargd556cc32019-09-17 01:21:23 -06002204}
2205
2206bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2207 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002208 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002209 // Always update common data
2210 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2211 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2212 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2213
2214 return false;
2215}
2216
2217// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2218void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2219 VkDescriptorSet *pDescriptorSets, VkResult result,
2220 void *ads_state_data) {
2221 if (VK_SUCCESS != result) return;
2222 // All the updates are contained in a single cvdescriptorset function
2223 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2224 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002225 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2226 if (pool_state) {
2227 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2228 }
locke-lunargd556cc32019-09-17 01:21:23 -06002229}
2230
2231void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2232 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002233 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2234 if (pool_state) {
2235 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002236 }
2237}
2238
2239void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2240 const VkWriteDescriptorSet *pDescriptorWrites,
2241 uint32_t descriptorCopyCount,
2242 const VkCopyDescriptorSet *pDescriptorCopies) {
2243 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2244 pDescriptorCopies);
2245}
2246
2247void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002248 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002249 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002250 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002251 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002252 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002253 }
2254}
2255
locke-lunargd556cc32019-09-17 01:21:23 -06002256void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2257 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002258 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002259 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002260
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002261 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002262}
2263
2264void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002265 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002266 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002267
2268 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002269}
2270
2271void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2272 VkResult result) {
2273 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002274 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2275 if (cb_state) {
2276 cb_state->Reset();
2277 }
locke-lunargd556cc32019-09-17 01:21:23 -06002278 }
2279}
2280
2281CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2282 // initially assume everything is static state
2283 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2284
2285 if (ds) {
2286 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002287 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002288 }
2289 }
locke-lunargd556cc32019-09-17 01:21:23 -06002290 return flags;
2291}
2292
2293// Validation cache:
2294// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002295
2296void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2297 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002298 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002299 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002300 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002301
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002302 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002303 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002304 const auto &create_info = pipe_state->create_info.graphics;
2305 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2306 const auto *viewport_state = create_info.pViewportState;
2307 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002308 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002309 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002310 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002311 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002312
2313 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002314 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2315 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002316 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002317 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002318 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002319 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002320 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002321 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002322
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002323 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002324 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2325 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2326 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002327 if (!has_dynamic_viewport_count) {
2328 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002329 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002330 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2331 // should become = ~uint32_t(0) if the other interpretation is correct.
2332 }
2333 }
2334 if (!has_dynamic_scissor_count) {
2335 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002336 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002337 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2338 // should become = ~uint32_t(0) if the other interpretation is correct.
2339 }
2340 }
locke-lunargd556cc32019-09-17 01:21:23 -06002341 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002342 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002343 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002344 if (!disabled[command_buffer_state]) {
2345 cb_state->AddChild(pipe_state);
2346 }
locke-lunargd556cc32019-09-17 01:21:23 -06002347}
2348
2349void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2350 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002351 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002352 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002353 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2354 cb_state->viewportMask |= bits;
2355 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002356
2357 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2358 for (size_t i = 0; i < viewportCount; ++i) {
2359 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2360 }
locke-lunargd556cc32019-09-17 01:21:23 -06002361}
2362
2363void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2364 uint32_t exclusiveScissorCount,
2365 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002366 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002367 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002368 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2369 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002370}
2371
2372void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2373 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002374 if (disabled[command_buffer_state]) return;
2375
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002376 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002377 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002378
2379 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002380 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002381 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002382 }
2383}
2384
2385void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2386 uint32_t viewportCount,
2387 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002388 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002389 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002390 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2391 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002392}
2393
2394void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2395 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2396 const VkAllocationCallbacks *pAllocator,
2397 VkAccelerationStructureNV *pAccelerationStructure,
2398 VkResult result) {
2399 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002400 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002401}
2402
Jeff Bolz95176d02020-04-01 00:36:16 -05002403void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2404 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2405 const VkAllocationCallbacks *pAllocator,
2406 VkAccelerationStructureKHR *pAccelerationStructure,
2407 VkResult result) {
2408 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002409 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2410 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002411}
2412
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002413void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2414 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2415 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2416 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2417 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002418 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002419 if (dst_as_state != nullptr) {
2420 dst_as_state->Build(&pInfos[i]);
2421 }
2422 }
2423}
2424
sourav parmarcd5fb182020-07-17 12:58:44 -07002425void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2426 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2427 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002428 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002429 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002430 return;
2431 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002432 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002433 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002434 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002435 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002436 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002437 if (!disabled[command_buffer_state]) {
2438 cb_state->AddChild(dst_as_state);
2439 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002440 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002441 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002442 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002443 if (src_as_state != nullptr) {
2444 cb_state->AddChild(src_as_state);
2445 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002446 }
2447 }
2448 cb_state->hasBuildAccelerationStructureCmd = true;
2449}
2450
2451void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2452 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2453 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2454 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002455 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2456 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002457 return;
2458 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002459 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002460 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002461 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002462 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002463 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002464 if (!disabled[command_buffer_state]) {
2465 cb_state->AddChild(dst_as_state);
2466 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002467 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002468 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002469 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002470 if (src_as_state != nullptr) {
2471 cb_state->AddChild(src_as_state);
2472 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002473 }
2474 }
2475 cb_state->hasBuildAccelerationStructureCmd = true;
2476}
locke-lunargd556cc32019-09-17 01:21:23 -06002477void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002478 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002479 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002480 if (as_state != nullptr) {
2481 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002482 as_state->memory_requirements_checked = true;
2483 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002484 as_state->build_scratch_memory_requirements_checked = true;
2485 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002486 as_state->update_scratch_memory_requirements_checked = true;
2487 }
2488 }
2489}
2490
sourav parmarcd5fb182020-07-17 12:58:44 -07002491void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2492 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002493 if (VK_SUCCESS != result) return;
2494 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002495 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002496
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002497 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002498 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002499 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002500 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002501 if (mem_state) {
2502 as_state->SetMemBinding(mem_state, info.memoryOffset);
2503 }
locke-lunargd556cc32019-09-17 01:21:23 -06002504
2505 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002506 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002507 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002508 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2509 }
2510 }
2511 }
2512}
2513
2514void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2515 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2516 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002517 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2518 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002519 return;
2520 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002521 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002522
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002523 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002524 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002525 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002526 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002527 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002528 }
locke-lunargd556cc32019-09-17 01:21:23 -06002529 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002530 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002531 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002532 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002533 cb_state->AddChild(src_as_state);
2534 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002535 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2536 if (instance_buffer) {
2537 cb_state->AddChild(instance_buffer);
2538 }
2539 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2540 if (scratch_buffer) {
2541 cb_state->AddChild(scratch_buffer);
2542 }
2543
2544 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2545 const auto& geom = pInfo->pGeometries[i];
2546
2547 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2548 if (vertex_buffer) {
2549 cb_state->AddChild(vertex_buffer);
2550 }
2551 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2552 if (index_buffer) {
2553 cb_state->AddChild(index_buffer);
2554 }
2555 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2556 if (transform_buffer) {
2557 cb_state->AddChild(transform_buffer);
2558 }
2559
2560 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2561 if (aabb_buffer) {
2562 cb_state->AddChild(aabb_buffer);
2563 }
2564 }
2565
locke-lunargd556cc32019-09-17 01:21:23 -06002566 }
2567 cb_state->hasBuildAccelerationStructureCmd = true;
2568}
2569
2570void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2571 VkAccelerationStructureNV dst,
2572 VkAccelerationStructureNV src,
2573 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002574 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002575 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002576 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2577 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002578 if (!disabled[command_buffer_state]) {
2579 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2580 }
locke-lunargd556cc32019-09-17 01:21:23 -06002581 if (dst_as_state != nullptr && src_as_state != nullptr) {
2582 dst_as_state->built = true;
2583 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002584 }
2585 }
2586}
2587
Jeff Bolz95176d02020-04-01 00:36:16 -05002588void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2589 VkAccelerationStructureKHR accelerationStructure,
2590 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002591 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002592}
2593
Jeff Bolz95176d02020-04-01 00:36:16 -05002594void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2595 VkAccelerationStructureNV accelerationStructure,
2596 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002597 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002598}
2599
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002600void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2601 uint32_t viewportCount,
2602 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002603 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002604 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002605}
2606
locke-lunargd556cc32019-09-17 01:21:23 -06002607void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002608 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002609 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002610}
2611
2612void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2613 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002614 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002615 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002616}
2617
2618void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2619 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002620 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002621 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002622}
2623
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002624void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2625 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002626 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002627 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002628 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2629 cb_state->scissorMask |= bits;
2630 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002631}
2632
locke-lunargd556cc32019-09-17 01:21:23 -06002633void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002634 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002635 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002636}
2637
2638void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2639 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002640 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002641 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002642}
2643
2644void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2645 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002646 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002647 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002648}
2649
2650void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2651 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002652 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002653 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002654}
2655
2656void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2657 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002658 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002659 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002660}
2661
locke-lunargd556cc32019-09-17 01:21:23 -06002662// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2663void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2664 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2665 uint32_t firstSet, uint32_t setCount,
2666 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2667 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002668 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002669 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002670 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002671 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002672
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002673 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2674 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002675}
2676
locke-lunargd556cc32019-09-17 01:21:23 -06002677void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2678 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2679 uint32_t set, uint32_t descriptorWriteCount,
2680 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002681 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002682 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002683 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002684}
2685
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002686void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2687 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2688 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002689 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2690 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002691 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002692 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2693 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002694
2695 auto &push_constant_data = cb_state->push_constant_data;
2696 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2697 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002698 cb_state->push_constant_pipeline_layout_set = layout;
2699
2700 auto flags = stageFlags;
2701 uint32_t bit_shift = 0;
2702 while (flags) {
2703 if (flags & 1) {
2704 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2705 const auto it = cb_state->push_constant_data_update.find(flag);
2706
2707 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002708 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002709 }
2710 }
2711 flags = flags >> 1;
2712 ++bit_shift;
2713 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002714 }
2715}
2716
locke-lunargd556cc32019-09-17 01:21:23 -06002717void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2718 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002719 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002720
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002721 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002722 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002723 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002724 cb_state->index_buffer_binding.offset = offset;
2725 cb_state->index_buffer_binding.index_type = indexType;
2726 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002727 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002728 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002729 }
locke-lunargd556cc32019-09-17 01:21:23 -06002730}
2731
2732void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2733 uint32_t bindingCount, const VkBuffer *pBuffers,
2734 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002735 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002736 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002737
2738 uint32_t end = firstBinding + bindingCount;
2739 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2740 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2741 }
2742
2743 for (uint32_t i = 0; i < bindingCount; ++i) {
2744 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002745 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002746 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002747 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2748 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002749 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002750 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002751 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002752 }
locke-lunargd556cc32019-09-17 01:21:23 -06002753 }
2754}
2755
2756void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2757 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002758 if (disabled[command_buffer_state]) return;
2759
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002760 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002761 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002762}
2763
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002764void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2765 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002766 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002767 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002768}
2769
2770void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2771 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002772 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002773 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2774
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002775 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2776 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002777}
2778
Tony-LunarGc43525f2021-11-15 16:12:38 -07002779void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2780 const VkDependencyInfo* pDependencyInfo) {
2781 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2782 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2783
2784 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2785 cb_state->RecordBarriers(*pDependencyInfo);
2786}
2787
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002788void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2789 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002790 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002791 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002792}
2793
2794void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2795 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002796 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002797 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002798}
2799
Tony-LunarGa2662db2021-11-16 07:26:24 -07002800void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2801 VkPipelineStageFlags2 stageMask) {
2802 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2803 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2804}
2805
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002806void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2807 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2808 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2809 uint32_t bufferMemoryBarrierCount,
2810 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2811 uint32_t imageMemoryBarrierCount,
2812 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002813 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2814 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002815 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2816 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002817}
2818
2819void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2820 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002821 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002822 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002823 const auto &dep_info = pDependencyInfos[i];
2824 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2825 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2826 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002827 }
2828}
2829
Tony-LunarG1364cf52021-11-17 16:10:11 -07002830void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2831 const VkDependencyInfo *pDependencyInfos) {
2832 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2833 for (uint32_t i = 0; i < eventCount; i++) {
2834 const auto &dep_info = pDependencyInfos[i];
2835 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2836 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2837 cb_state->RecordBarriers(dep_info);
2838 }
2839}
2840
Jeremy Gebben79649152021-06-22 14:46:24 -06002841void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2842 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2843 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2844 uint32_t bufferMemoryBarrierCount,
2845 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2846 uint32_t imageMemoryBarrierCount,
2847 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002848 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002849 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2850 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2851 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002852}
2853
2854void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2855 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002856 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002857 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2858 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002859}
2860
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002861void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2862 const VkDependencyInfo *pDependencyInfo) {
2863 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2864 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2865 cb_state->RecordBarriers(*pDependencyInfo);
2866}
2867
locke-lunargd556cc32019-09-17 01:21:23 -06002868void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2869 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002870 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002871
locke-lunargd556cc32019-09-17 01:21:23 -06002872 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002873 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002874 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002875 if (!disabled[query_validation]) {
2876 cb_state->BeginQuery(query);
2877 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002878 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002879 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002880 cb_state->AddChild(pool_state);
2881 }
locke-lunargd556cc32019-09-17 01:21:23 -06002882}
2883
2884void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002885 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002886 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002887 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002888 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002889 if (!disabled[query_validation]) {
2890 cb_state->EndQuery(query_obj);
2891 }
2892 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002893 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002894 cb_state->AddChild(pool_state);
2895 }
locke-lunargd556cc32019-09-17 01:21:23 -06002896}
2897
2898void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2899 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002900 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002901 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002902
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002903 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002904 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002905
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002906 if (!disabled[command_buffer_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);
2909 }
locke-lunargd556cc32019-09-17 01:21:23 -06002910}
2911
2912void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2913 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2914 VkDeviceSize dstOffset, VkDeviceSize stride,
2915 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002916 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2917
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002918 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002919 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002920 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002921 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002922 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002923 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002924}
2925
2926void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2927 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002928 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002929 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002930}
2931
2932void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2933 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2934 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002935 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002936 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002937}
2938
Tony-LunarGde9936b2021-11-17 15:34:11 -07002939void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
2940 VkQueryPool queryPool, uint32_t slot) {
2941 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2942 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
2943}
2944
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002945void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
2946 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
2947 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
2948 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002949 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002950 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002951 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002952 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002953 cb_state->AddChild(pool_state);
2954 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002955 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002956}
2957
locke-lunargd556cc32019-09-17 01:21:23 -06002958void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
2959 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
2960 VkResult result) {
2961 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002962
Jeremy Gebben88f58142021-06-01 10:07:52 -06002963 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002964 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002965 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002966
locke-lunargd556cc32019-09-17 01:21:23 -06002967 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002968 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002969 }
2970 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06002971
Jeremy Gebben9f537102021-10-05 16:37:12 -06002972 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06002973 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06002974}
2975
locke-lunargd556cc32019-09-17 01:21:23 -06002976void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
2977 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2978 VkResult result) {
2979 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002980 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002981}
2982
Mike Schuchardt2df08912020-12-15 16:28:09 -08002983void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002984 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2985 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002986 if (VK_SUCCESS != result) return;
2987
Jeremy Gebben082a9832021-10-28 13:40:11 -06002988 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002989}
2990
Mike Schuchardt2df08912020-12-15 16:28:09 -08002991void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002992 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2993 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002994 if (VK_SUCCESS != result) return;
2995
Jeremy Gebben082a9832021-10-28 13:40:11 -06002996 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002997}
2998
locke-lunargd556cc32019-09-17 01:21:23 -06002999void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3000 const VkRenderPassBeginInfo *pRenderPassBegin,
3001 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003002 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003003 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003004}
3005
3006void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3007 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003008 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003009 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003010 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003011}
3012
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003013void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3014 uint32_t counterBufferCount,
3015 const VkBuffer *pCounterBuffers,
3016 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003017 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003018
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003019 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003020 cb_state->transform_feedback_active = true;
3021}
3022
3023void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3024 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3025 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003026 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003027
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003028 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003029 cb_state->transform_feedback_active = false;
3030}
3031
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003032void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3033 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003034 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003035
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003036 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003037 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003038 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3039 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003040}
3041
3042void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003043 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003044
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003045 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003046 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003047 cb_state->conditional_rendering_inside_render_pass = false;
3048 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003049}
3050
amhagana448ea52021-11-02 14:09:14 -04003051void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003052 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003053 cb_state->activeRenderPass = nullptr;
3054}
3055
3056void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3057 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003058 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003059 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3060}
3061
Tony-LunarG40b33882021-12-02 12:40:11 -07003062void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3063 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3064 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3065}
3066
amhagana448ea52021-11-02 14:09:14 -04003067void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3068 RecordCmdEndRenderingRenderPassState(commandBuffer);
3069}
3070
Tony-LunarG40b33882021-12-02 12:40:11 -07003071void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3072 RecordCmdEndRenderingRenderPassState(commandBuffer);
3073}
3074
Tony-LunarG977448c2019-12-02 14:52:02 -07003075void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3076 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003077 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003078 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003079 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003080}
3081
locke-lunargd556cc32019-09-17 01:21:23 -06003082void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003083 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003084 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003085}
3086
3087void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003088 const VkSubpassBeginInfo *pSubpassBeginInfo,
3089 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003090 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003091 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003092}
3093
Tony-LunarG977448c2019-12-02 14:52:02 -07003094void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003095 const VkSubpassBeginInfo *pSubpassBeginInfo,
3096 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003097 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003098 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003099}
3100
3101void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003102 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003103 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003104}
3105
3106void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003107 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003108 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003109 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003110}
3111
Tony-LunarG977448c2019-12-02 14:52:02 -07003112void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003113 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003114 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003115 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003116}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003117
locke-lunargd556cc32019-09-17 01:21:23 -06003118void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3119 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003120 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003121
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003122 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003123}
3124
3125void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3126 VkFlags flags, void **ppData, VkResult result) {
3127 if (VK_SUCCESS != result) return;
3128 RecordMappedMemory(mem, offset, size, ppData);
3129}
3130
3131void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003132 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003133 if (mem_info) {
3134 mem_info->mapped_range = MemRange();
3135 mem_info->p_driver_data = nullptr;
3136 }
3137}
3138
3139void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003140 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003141 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003142 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3143 // See: VUID-vkGetImageSubresourceLayout-image-01895
3144 image_state->fragment_encoder =
3145 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003146 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003147 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003148 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003149 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003150 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003151
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003152 if (!swapchain_image.fake_base_address) {
3153 auto size = image_state->fragment_encoder->TotalSize();
3154 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003155 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003156 // All images bound to this swapchain and index are aliases
3157 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003158 }
3159 } else {
3160 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003161 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003162 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003163 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003164 }
locke-lunargd556cc32019-09-17 01:21:23 -06003165 }
locke-lunargd556cc32019-09-17 01:21:23 -06003166 }
3167}
3168
3169void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3170 VkDeviceSize memoryOffset, VkResult result) {
3171 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003172 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003173 bind_info.image = image;
3174 bind_info.memory = mem;
3175 bind_info.memoryOffset = memoryOffset;
3176 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003177}
3178
3179void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003180 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003181 if (VK_SUCCESS != result) return;
3182 for (uint32_t i = 0; i < bindInfoCount; i++) {
3183 UpdateBindImageMemoryState(pBindInfos[i]);
3184 }
3185}
3186
3187void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003188 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003189 if (VK_SUCCESS != result) return;
3190 for (uint32_t i = 0; i < bindInfoCount; i++) {
3191 UpdateBindImageMemoryState(pBindInfos[i]);
3192 }
3193}
3194
3195void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003196 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003197 if (event_state) {
3198 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3199 }
locke-lunargd556cc32019-09-17 01:21:23 -06003200}
3201
3202void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3203 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3204 VkResult result) {
3205 if (VK_SUCCESS != result) return;
3206 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3207 pImportSemaphoreFdInfo->flags);
3208}
3209
3210void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003211 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003212 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003213 if (semaphore_state) {
3214 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003215 }
3216}
3217
3218#ifdef VK_USE_PLATFORM_WIN32_KHR
3219void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3220 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3221 if (VK_SUCCESS != result) return;
3222 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3223 pImportSemaphoreWin32HandleInfo->flags);
3224}
3225
3226void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3227 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3228 HANDLE *pHandle, VkResult result) {
3229 if (VK_SUCCESS != result) return;
3230 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3231}
3232
3233void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3234 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3235 if (VK_SUCCESS != result) return;
3236 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3237 pImportFenceWin32HandleInfo->flags);
3238}
3239
3240void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3241 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3242 HANDLE *pHandle, VkResult result) {
3243 if (VK_SUCCESS != result) return;
3244 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3245}
3246#endif
3247
3248void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3249 VkResult result) {
3250 if (VK_SUCCESS != result) return;
3251 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3252}
3253
Mike Schuchardt2df08912020-12-15 16:28:09 -08003254void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3255 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003256 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003257
3258 if (fence_node) {
3259 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003260 }
3261}
3262
3263void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3264 VkResult result) {
3265 if (VK_SUCCESS != result) return;
3266 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3267}
3268
Mike Schuchardt2df08912020-12-15 16:28:09 -08003269void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003270 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003271 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003272 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003273 }
3274}
3275
3276void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3277 VkResult result) {
3278 if (VK_SUCCESS != result) return;
3279 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3280}
3281
3282void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3283 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3284 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003285 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003286}
3287
3288void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003289 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003290 SWAPCHAIN_NODE *old_swapchain_state) {
3291 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003292 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003293 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003294 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003295 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3296 surface_state->AddParent(swapchain.get());
3297 surface_state->swapchain = swapchain.get();
3298 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003299 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003300 } else {
3301 surface_state->swapchain = nullptr;
3302 }
3303 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003304 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003305 if (old_swapchain_state) {
3306 old_swapchain_state->retired = true;
3307 }
3308 return;
3309}
3310
3311void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3312 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3313 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003314 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003315 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003316 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003317}
3318
3319void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3320 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003321 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003322}
3323
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003324void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3325 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3326 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3327 VkResult result) {
3328 if (VK_SUCCESS != result) return;
3329 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003330 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003331}
3332
locke-lunargd556cc32019-09-17 01:21:23 -06003333void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003334 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003335 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3336 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003337 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003338 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003339 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003340 }
3341 }
3342
Tony-LunarG6f887e52021-07-27 11:23:14 -06003343 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003344 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3345 // 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
3346 // confused itself just as much.
3347 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3348 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3349 // Mark the image as having been released to the WSI
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003350 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003351 if (swapchain_data) {
3352 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003353 if (present_id_info) {
3354 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3355 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3356 }
3357 }
locke-lunargd556cc32019-09-17 01:21:23 -06003358 }
3359 }
locke-lunargd556cc32019-09-17 01:21:23 -06003360}
3361
3362void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3363 const VkSwapchainCreateInfoKHR *pCreateInfos,
3364 const VkAllocationCallbacks *pAllocator,
3365 VkSwapchainKHR *pSwapchains, VkResult result) {
3366 if (pCreateInfos) {
3367 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003368 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003369 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003370 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3371 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003372 }
3373 }
3374}
3375
3376void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3377 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003378 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003379 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003380 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3381 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003382 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003383 }
3384
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003385 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003386 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003387 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3388 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003389 semaphore_state->EnqueueAcquire();
locke-lunargd556cc32019-09-17 01:21:23 -06003390 }
3391
3392 // Mark the image as acquired.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003393 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003394 if (swapchain_data) {
3395 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003396 }
3397}
3398
3399void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3400 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3401 VkResult result) {
3402 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3403 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3404}
3405
3406void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3407 uint32_t *pImageIndex, VkResult result) {
3408 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3409 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3410 pAcquireInfo->fence, pImageIndex);
3411}
3412
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003413std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3414 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3415}
3416
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003417void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3418 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3419 VkResult result) {
3420 if (result != VK_SUCCESS) {
3421 return;
3422 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003423 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003424 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003425 // this can fail if the allocator fails
3426 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3427 if (result != VK_SUCCESS) {
3428 return;
3429 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003430 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003431 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3432 if (result != VK_SUCCESS) {
3433 return;
3434 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003435
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003436 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003437 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003438 }
3439}
3440
3441// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003442static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003443 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003444}
3445
3446void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3447 uint32_t *pQueueFamilyPropertyCount,
3448 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003449 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3450 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003451 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003452}
3453
3454void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003455 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003456 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3457 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003458 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003459}
3460
3461void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003462 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003463 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3464 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003465 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003466}
3467void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3468 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003469 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003470}
3471
Jeremy Gebben082a9832021-10-28 13:40:11 -06003472void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003473
3474void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3475 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3476 const VkAllocationCallbacks *pAllocator,
3477 VkSurfaceKHR *pSurface, VkResult result) {
3478 if (VK_SUCCESS != result) return;
3479 RecordVulkanSurface(pSurface);
3480}
3481
3482#ifdef VK_USE_PLATFORM_ANDROID_KHR
3483void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3484 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3485 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3486 VkResult result) {
3487 if (VK_SUCCESS != result) return;
3488 RecordVulkanSurface(pSurface);
3489}
3490#endif // VK_USE_PLATFORM_ANDROID_KHR
3491
3492#ifdef VK_USE_PLATFORM_IOS_MVK
3493void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3494 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3495 VkResult result) {
3496 if (VK_SUCCESS != result) return;
3497 RecordVulkanSurface(pSurface);
3498}
3499#endif // VK_USE_PLATFORM_IOS_MVK
3500
3501#ifdef VK_USE_PLATFORM_MACOS_MVK
3502void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3503 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3504 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3505 VkResult result) {
3506 if (VK_SUCCESS != result) return;
3507 RecordVulkanSurface(pSurface);
3508}
3509#endif // VK_USE_PLATFORM_MACOS_MVK
3510
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003511#ifdef VK_USE_PLATFORM_METAL_EXT
3512void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3513 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3514 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3515 VkResult result) {
3516 if (VK_SUCCESS != result) return;
3517 RecordVulkanSurface(pSurface);
3518}
3519#endif // VK_USE_PLATFORM_METAL_EXT
3520
locke-lunargd556cc32019-09-17 01:21:23 -06003521#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3522void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3523 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3524 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3525 VkResult result) {
3526 if (VK_SUCCESS != result) return;
3527 RecordVulkanSurface(pSurface);
3528}
3529#endif // VK_USE_PLATFORM_WAYLAND_KHR
3530
3531#ifdef VK_USE_PLATFORM_WIN32_KHR
3532void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3533 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3534 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3535 VkResult result) {
3536 if (VK_SUCCESS != result) return;
3537 RecordVulkanSurface(pSurface);
3538}
3539#endif // VK_USE_PLATFORM_WIN32_KHR
3540
3541#ifdef VK_USE_PLATFORM_XCB_KHR
3542void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3543 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3544 VkResult result) {
3545 if (VK_SUCCESS != result) return;
3546 RecordVulkanSurface(pSurface);
3547}
3548#endif // VK_USE_PLATFORM_XCB_KHR
3549
3550#ifdef VK_USE_PLATFORM_XLIB_KHR
3551void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3552 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3553 VkResult result) {
3554 if (VK_SUCCESS != result) return;
3555 RecordVulkanSurface(pSurface);
3556}
3557#endif // VK_USE_PLATFORM_XLIB_KHR
3558
Niklas Haas8b84af12020-04-19 22:20:11 +02003559void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3560 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3561 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3562 VkResult result) {
3563 if (VK_SUCCESS != result) return;
3564 RecordVulkanSurface(pSurface);
3565}
3566
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003567void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3568 VkSurfaceKHR surface,
3569 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3570 VkResult result) {
3571 if (VK_SUCCESS != result) return;
3572 auto surface_state = Get<SURFACE_STATE>(surface);
3573 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3574}
3575
3576void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3577 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3578 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3579 if (VK_SUCCESS != result) return;
3580 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3581 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3582}
3583
3584void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3585 VkSurfaceKHR surface,
3586 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3587 VkResult result) {
3588 auto surface_state = Get<SURFACE_STATE>(surface);
3589 VkSurfaceCapabilitiesKHR caps{
3590 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3591 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3592 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3593 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3594 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3595 };
3596 surface_state->SetCapabilities(physicalDevice, caps);
3597}
3598
locke-lunargd556cc32019-09-17 01:21:23 -06003599void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3600 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3601 VkBool32 *pSupported, VkResult result) {
3602 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003603 auto surface_state = Get<SURFACE_STATE>(surface);
3604 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3605}
3606
3607void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3608 VkSurfaceKHR surface,
3609 uint32_t *pPresentModeCount,
3610 VkPresentModeKHR *pPresentModes,
3611 VkResult result) {
3612 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3613
3614 if (pPresentModes) {
3615 auto surface_state = Get<SURFACE_STATE>(surface);
3616 surface_state->SetPresentModes(physicalDevice,
3617 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3618 }
3619}
3620
3621void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3622 uint32_t *pSurfaceFormatCount,
3623 VkSurfaceFormatKHR *pSurfaceFormats,
3624 VkResult result) {
3625 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3626
3627 if (pSurfaceFormats) {
3628 auto surface_state = Get<SURFACE_STATE>(surface);
3629 surface_state->SetFormats(physicalDevice,
3630 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3631 }
3632}
3633
3634void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3635 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3636 uint32_t *pSurfaceFormatCount,
3637 VkSurfaceFormat2KHR *pSurfaceFormats,
3638 VkResult result) {
3639 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3640
3641 if (pSurfaceFormats) {
3642 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3643 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3644 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3645 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3646 }
3647 surface_state->SetFormats(physicalDevice, std::move(fmts));
3648 }
locke-lunargd556cc32019-09-17 01:21:23 -06003649}
3650
locke-lunargd556cc32019-09-17 01:21:23 -06003651void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3652 const VkDebugUtilsLabelEXT *pLabelInfo) {
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_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003655 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3656}
3657
3658void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003659 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003660 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003661 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3662}
3663
3664void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3665 const VkDebugUtilsLabelEXT *pLabelInfo) {
3666 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3667
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003668 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003669 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3670 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003671 cb_state->debug_label = LoggingLabel(pLabelInfo);
3672}
3673
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003674void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3675 uint32_t queueFamilyIndex,
3676 uint32_t *pCounterCount,
3677 VkPerformanceCounterKHR *pCounters) {
3678 if (NULL == pCounters) return;
3679
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003680 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3681 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003682
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003683 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3684 queue_family_counters->counters.resize(*pCounterCount);
3685 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003686
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003687 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003688}
3689
3690void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3691 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3692 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3693 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3694 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3695}
3696
3697void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3698 VkResult result) {
3699 if (result == VK_SUCCESS) performance_lock_acquired = true;
3700}
3701
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003702void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3703 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003704 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003705 cmd_buffer.second->performance_lock_released = true;
3706 }
3707}
3708
locke-lunargd556cc32019-09-17 01:21:23 -06003709void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003710 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003711 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003712 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003713}
3714
3715void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003716 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003717 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003718 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003719}
3720
Mike Schuchardt2df08912020-12-15 16:28:09 -08003721void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3722 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003723 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003724}
3725
Mike Schuchardt2df08912020-12-15 16:28:09 -08003726void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3727 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3728 const VkAllocationCallbacks *pAllocator,
3729 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3730 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003731 if (VK_SUCCESS != result) return;
3732 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3733}
3734
3735void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003736 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3737 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003738 if (VK_SUCCESS != result) return;
3739 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3740}
3741
3742void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003743 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003744 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003745 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3746 assert(template_state);
3747 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003748 // TODO: Record template push descriptor updates
3749 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003750 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003751 }
3752 }
3753}
3754
3755void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3756 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3757 const void *pData) {
3758 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3759}
3760
3761void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003762 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003763 const void *pData) {
3764 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3765}
3766
Mike Schuchardt2df08912020-12-15 16:28:09 -08003767void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3768 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3769 VkPipelineLayout layout, uint32_t set,
3770 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003771 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003772
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003773 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003774 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003775 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003776 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003777 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003778 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003779 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003780 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003781 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003782 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003783 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3784 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003785 }
3786}
3787
3788void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3789 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003790 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003791 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003792 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003793 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003794 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003795 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003796 }
3797}
3798
3799void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3800 uint32_t *pPropertyCount,
3801 VkDisplayPlanePropertiesKHR *pProperties,
3802 VkResult result) {
3803 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3804 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3805}
3806
3807void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3808 uint32_t *pPropertyCount,
3809 VkDisplayPlaneProperties2KHR *pProperties,
3810 VkResult result) {
3811 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3812 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3813}
3814
3815void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3816 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3817 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003818 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003819 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003820 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003821}
3822
3823void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3824 uint32_t query, uint32_t index) {
3825 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003826 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003827 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003828 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003829}
3830
3831void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3832 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003833 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003834
3835 if (create_info->format != VK_FORMAT_UNDEFINED) {
3836 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003837 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003838 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3839 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003840 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003841
Jeremy Gebben082a9832021-10-28 13:40:11 -06003842 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003843}
3844
3845void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3846 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3847 const VkAllocationCallbacks *pAllocator,
3848 VkSamplerYcbcrConversion *pYcbcrConversion,
3849 VkResult result) {
3850 if (VK_SUCCESS != result) return;
3851 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3852}
3853
3854void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3855 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3856 const VkAllocationCallbacks *pAllocator,
3857 VkSamplerYcbcrConversion *pYcbcrConversion,
3858 VkResult result) {
3859 if (VK_SUCCESS != result) return;
3860 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3861}
3862
3863void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3864 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003865 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003866}
3867
3868void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3869 VkSamplerYcbcrConversion ycbcrConversion,
3870 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003871 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003872}
3873
Tony-LunarG977448c2019-12-02 14:52:02 -07003874void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3875 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003876 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003877 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003878
3879 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003880 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003881 if (!query_pool_state) return;
3882
3883 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003884 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3885 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003886 auto query_index = firstQuery + i;
3887 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003888 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003889 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003890 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003891 }
3892 }
locke-lunargd556cc32019-09-17 01:21:23 -06003893 }
3894}
3895
Tony-LunarG977448c2019-12-02 14:52:02 -07003896void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3897 uint32_t queryCount) {
3898 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3899}
3900
3901void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3902 uint32_t queryCount) {
3903 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3904}
3905
locke-lunargd556cc32019-09-17 01:21:23 -06003906void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003907 const UPDATE_TEMPLATE_STATE *template_state,
3908 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003909 // Translate the templated update into a normal update for validation...
3910 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3911 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3912 decoded_update.desc_writes.data(), 0, NULL);
3913}
3914
3915// Update the common AllocateDescriptorSetsData
3916void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003917 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003918 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003919 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003920 if (layout) {
3921 ds_data->layout_nodes[i] = layout;
3922 // Count total descriptors required per type
3923 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3924 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003925 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3926 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003927 }
3928 }
3929 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3930 }
3931}
3932
locke-lunargd556cc32019-09-17 01:21:23 -06003933void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3934 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003935 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003936 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003937}
3938
Tony-LunarG745150c2021-07-02 15:07:31 -06003939void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3940 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3941 uint32_t firstInstance, uint32_t stride) {
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_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003944}
3945
locke-lunargd556cc32019-09-17 01:21:23 -06003946void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
3947 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
3948 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003949 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003950 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003951}
3952
Tony-LunarG745150c2021-07-02 15:07:31 -06003953void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3954 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
3955 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
3956 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003957 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003958 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003959}
3960
locke-lunargd556cc32019-09-17 01:21:23 -06003961void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3962 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003963 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003964 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003965 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003966 if (!disabled[command_buffer_state]) {
3967 cb_state->AddChild(buffer_state);
3968 }
locke-lunargd556cc32019-09-17 01:21:23 -06003969}
3970
3971void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3972 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003973 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003974 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003975 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003976 if (!disabled[command_buffer_state]) {
3977 cb_state->AddChild(buffer_state);
3978 }
locke-lunargd556cc32019-09-17 01:21:23 -06003979}
3980
3981void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003982 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003983 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06003984}
3985
3986void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3987 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003988 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003989 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003990 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003991 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003992 cb_state->AddChild(buffer_state);
3993 }
locke-lunargd556cc32019-09-17 01:21:23 -06003994}
3995
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003996void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3997 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003998 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003999 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4000}
4001
4002void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4003 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004004 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004005 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4006}
4007
Tony-LunarG977448c2019-12-02 14:52:02 -07004008void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4009 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004010 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004011 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004012 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004013 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004014 auto buffer_state = Get<BUFFER_STATE>(buffer);
4015 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004016 cb_state->AddChild(buffer_state);
4017 cb_state->AddChild(count_buffer_state);
4018 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004019}
4020
locke-lunargd556cc32019-09-17 01:21:23 -06004021void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4022 VkDeviceSize offset, VkBuffer countBuffer,
4023 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4024 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004025 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004026 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004027}
4028
4029void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4030 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4031 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004032 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004033 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004034}
4035
4036void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4037 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004038 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004039 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004040 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004041 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004042 auto buffer_state = Get<BUFFER_STATE>(buffer);
4043 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004044 cb_state->AddChild(buffer_state);
4045 cb_state->AddChild(count_buffer_state);
4046 }
locke-lunargd556cc32019-09-17 01:21:23 -06004047}
4048
4049void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4050 VkDeviceSize offset, VkBuffer countBuffer,
4051 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4052 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004053 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004054 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004055}
4056
4057void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4058 VkDeviceSize offset, VkBuffer countBuffer,
4059 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4060 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004061 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004062 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004063}
4064
4065void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4066 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004067 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004068 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004069}
4070
4071void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4072 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004073 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004074 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004075 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004076 if (!disabled[command_buffer_state] && buffer_state) {
4077 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004078 }
4079}
4080
4081void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4082 VkDeviceSize offset, VkBuffer countBuffer,
4083 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4084 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004085 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004086 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004087 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004088 auto buffer_state = Get<BUFFER_STATE>(buffer);
4089 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004090 if (buffer_state) {
4091 cb_state->AddChild(buffer_state);
4092 }
4093 if (count_buffer_state) {
4094 cb_state->AddChild(count_buffer_state);
4095 }
locke-lunargd556cc32019-09-17 01:21:23 -06004096 }
4097}
4098
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004099void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4100 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4101 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4102 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4103 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4104 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4105 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004106 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004107 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004108 cb_state->hasTraceRaysCmd = true;
4109}
4110
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004111void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4112 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4113 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4114 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4115 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4116 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004117 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004118 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004119 cb_state->hasTraceRaysCmd = true;
4120}
4121
4122void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4123 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4124 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4125 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4126 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4127 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004128 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004129 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004130 cb_state->hasTraceRaysCmd = true;
4131}
4132
locke-lunargd556cc32019-09-17 01:21:23 -06004133void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4134 const VkAllocationCallbacks *pAllocator,
4135 VkShaderModule *pShaderModule, VkResult result,
4136 void *csm_state_data) {
4137 if (VK_SUCCESS != result) return;
4138 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4139
sfricke-samsung45996a42021-09-16 13:45:27 -07004140 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004141 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004142 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4143 csm_state->unique_shader_id)
4144 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004145 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004146}
4147
John Zulauf22b0fbe2019-10-15 06:26:16 -06004148void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4149 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4150 VkResult result) {
4151 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004152 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004153
4154 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4155
4156 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004157 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004158 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004159 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004160
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004161 auto format_features = GetImageFormatFeatures(
4162 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4163 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004164
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06004165 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004166 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004167 if (!swapchain_image.fake_base_address) {
4168 auto size = image_state->fragment_encoder->TotalSize();
4169 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004170 }
4171
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004172 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004173 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004174 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004175 }
4176 }
4177
4178 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004179 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4180 }
4181}
sourav parmar35e7a002020-06-09 17:58:44 -07004182
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004183void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4184 const VkCopyAccelerationStructureInfoKHR *pInfo,
4185 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004186 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4187 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004188 if (dst_as_state != nullptr && src_as_state != nullptr) {
4189 dst_as_state->built = true;
4190 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4191 }
4192}
4193
sourav parmar35e7a002020-06-09 17:58:44 -07004194void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4195 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004196 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004197 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004198 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004199 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4200 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004201 if (dst_as_state != nullptr && src_as_state != nullptr) {
4202 dst_as_state->built = true;
4203 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004204 if (!disabled[command_buffer_state]) {
4205 cb_state->AddChild(dst_as_state);
4206 cb_state->AddChild(src_as_state);
4207 }
sourav parmar35e7a002020-06-09 17:58:44 -07004208 }
4209 }
4210}
Piers Daniell39842ee2020-07-10 16:42:33 -06004211
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004212void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4213 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4214 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4215 if (cb_state) {
4216 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4217 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4218 if (!disabled[command_buffer_state]) {
4219 cb_state->AddChild(src_as_state);
4220 }
4221 auto iter = buffer_address_map_.find(pInfo->dst.deviceAddress);
4222 if (iter != buffer_address_map_.end()) {
4223 cb_state->AddChild(iter->second);
4224 }
4225 }
4226}
4227
4228void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4229 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4230 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4231 if (cb_state) {
4232 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4233 if (!disabled[command_buffer_state]) {
4234 auto iter = buffer_address_map_.find(pInfo->src.deviceAddress);
4235 if (iter != buffer_address_map_.end()) {
4236 cb_state->AddChild(iter->second);
4237 }
4238 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4239 cb_state->AddChild(dst_as_state);
4240 }
4241 }
4242}
4243
Piers Daniell39842ee2020-07-10 16:42:33 -06004244void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004245 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004246 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004247}
4248
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004249void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4250 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4251 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4252}
4253
Piers Daniell39842ee2020-07-10 16:42:33 -06004254void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004255 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004256 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004257}
4258
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004259void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4260 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4261 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4262}
4263
Piers Daniell39842ee2020-07-10 16:42:33 -06004264void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4265 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004266 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004267 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004268 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004269}
4270
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004271void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4272 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004273 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004274 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4275 cb_state->primitiveTopology = primitiveTopology;
4276}
4277
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004278void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4279 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004280 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4281 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004282 uint32_t bits = (1u << viewportCount) - 1u;
4283 cb_state->viewportWithCountMask |= bits;
4284 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004285 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004286 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004287
4288 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4289 for (size_t i = 0; i < viewportCount; ++i) {
4290 cb_state->dynamicViewports[i] = pViewports[i];
4291 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004292}
4293
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004294void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4295 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004296 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004297}
4298
4299void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004300 const VkViewport *pViewports) {
4301 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004302}
4303
4304void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4305 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004306 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004307 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004308 uint32_t bits = (1u << scissorCount) - 1u;
4309 cb_state->scissorWithCountMask |= bits;
4310 cb_state->trashedScissorMask &= ~bits;
4311 cb_state->scissorWithCountCount = scissorCount;
4312 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004313}
4314
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004315void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4316 const VkRect2D *pScissors) {
4317 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4318}
4319
4320void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4321 const VkRect2D *pScissors) {
4322 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4323}
4324
4325void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4326 uint32_t bindingCount, const VkBuffer *pBuffers,
4327 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4328 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004329 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004330 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004331
4332 uint32_t end = firstBinding + bindingCount;
4333 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4334 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4335 }
4336
4337 for (uint32_t i = 0; i < bindingCount; ++i) {
4338 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004339 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004340 vertex_buffer_binding.offset = pOffsets[i];
4341 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4342 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4343 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004344 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004345 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004346 }
4347 }
4348}
4349
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004350void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4351 uint32_t bindingCount, const VkBuffer *pBuffers,
4352 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4353 const VkDeviceSize *pStrides) {
4354 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4355 CMD_BINDVERTEXBUFFERS2EXT);
4356}
4357
4358void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4359 uint32_t bindingCount, const VkBuffer *pBuffers,
4360 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4361 const VkDeviceSize *pStrides) {
4362 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4363 CMD_BINDVERTEXBUFFERS2);
4364}
4365
Piers Daniell39842ee2020-07-10 16:42:33 -06004366void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004367 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004368 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004369}
4370
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004371void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4372 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4373 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4374}
4375
Piers Daniell39842ee2020-07-10 16:42:33 -06004376void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004377 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004378 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004379}
4380
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004381void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4382 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4383 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4384}
4385
Piers Daniell39842ee2020-07-10 16:42:33 -06004386void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004387 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004388 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004389}
4390
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004391void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4392 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4393 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4394}
4395
Piers Daniell39842ee2020-07-10 16:42:33 -06004396void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4397 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004398 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004399 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004400}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004401
4402void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4403 VkBool32 depthBoundsTestEnable) {
4404 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4405 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4406}
4407
Piers Daniell39842ee2020-07-10 16:42:33 -06004408void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004409 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004410 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004411}
4412
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004413void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4414 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4415 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4416}
4417
Piers Daniell39842ee2020-07-10 16:42:33 -06004418void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4419 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4420 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004421 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004422 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004423}
locke-lunarg4189aa22020-10-21 00:23:48 -06004424
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004425void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4426 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4427 VkCompareOp compareOp) {
4428 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4429 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4430}
4431
locke-lunarg4189aa22020-10-21 00:23:48 -06004432void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4433 uint32_t discardRectangleCount,
4434 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004435 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004436 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004437}
4438
4439void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4440 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004441 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004442 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004443}
4444
4445void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4446 VkCoarseSampleOrderTypeNV sampleOrderType,
4447 uint32_t customSampleOrderCount,
4448 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004449 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004450 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004451}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004452
4453void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004454 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004455 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004456}
4457
4458void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004459 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004460 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004461}
4462
4463void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4464 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004465 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004466 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004467}
4468
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004469void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4470 VkBool32 rasterizerDiscardEnable) {
4471 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4472 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4473}
4474
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004475void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004476 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004477 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004478}
4479
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004480void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4481 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4482 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4483}
4484
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004485void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4486 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004487 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004488 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004489}
Piers Daniell924cd832021-05-18 13:48:47 -06004490
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004491void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4492 VkBool32 primitiveRestartEnable) {
4493 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4494 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4495}
4496
Piers Daniell924cd832021-05-18 13:48:47 -06004497void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4498 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4499 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4500 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004501 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004502 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4503
4504 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4505 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4506 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004507 if (pipeline_state->create_info.graphics.pDynamicState) {
4508 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4509 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004510 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4511 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4512 break;
4513 }
4514 }
4515 }
4516 }
4517 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004518}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004519
4520void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004521 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004522 if (buffer_state && address != 0) {
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004523 // address is used for GPU-AV and ray tracing buffer validation
4524 buffer_state->deviceAddress = address;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06004525 buffer_address_map_.insert(address, buffer_state.get());
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004526 }
4527}
4528
4529void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4530 VkDeviceAddress address) {
4531 RecordGetBufferDeviceAddress(pInfo, address);
4532}
4533
4534void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4535 VkDeviceAddress address) {
4536 RecordGetBufferDeviceAddress(pInfo, address);
4537}
4538
4539void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4540 VkDeviceAddress address) {
4541 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004542}
4543
4544std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4545 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004546 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004547}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004548
4549std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4550 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004551 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004552 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4553}