blob: d238a885384b5e06139609b79441a3c5372264fb [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)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700338 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100339 // address is used for GPU-AV and ray tracing buffer validation
340 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700341 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100342 }
343 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600344 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600345}
346
347void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
348 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
349 VkResult result) {
350 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600351
Jeremy Gebben9f537102021-10-05 16:37:12 -0600352 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600353
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200354 VkFormatFeatureFlags2KHR buffer_features;
355 if (has_format_feature2) {
356 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
357 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
358 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
359 buffer_features = fmt_props_3.bufferFeatures;
360 } else {
361 VkFormatProperties format_properties;
362 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
363 buffer_features = format_properties.bufferFeatures;
364 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600365
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200366 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600367}
368
369void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
370 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
371 VkResult result) {
372 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600373 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700374
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200375 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600376 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700377 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600378 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700379 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200380 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
381 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
382 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700383 }
384
locke-lunarg9939d4b2020-10-26 20:11:08 -0600385 // 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 -0600386 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600387 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700388 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600389 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700390 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600391 image_format_info.type = image_state->createInfo.imageType;
392 image_format_info.format = image_state->createInfo.format;
393 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600394 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
395 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600396 image_format_info.flags = image_state->createInfo.flags;
397
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600398 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600399
400 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
401 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600402
Jeremy Gebben082a9832021-10-28 13:40:11 -0600403 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600404}
405
406void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
407 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600408 if (disabled[command_buffer_state]) return;
409
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700410 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600411 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600412}
413
Jeff Leger178b1e52020-10-05 12:22:23 -0400414void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600415 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600416 if (disabled[command_buffer_state]) return;
417
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700418 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600419 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
420 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400421}
422
Tony-LunarGef035472021-11-02 10:23:33 -0600423void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
424 if (disabled[command_buffer_state]) return;
425
426 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
427 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
428 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
429}
430
locke-lunargd556cc32019-09-17 01:21:23 -0600431void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
432 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600433 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600434}
435
436void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700437 auto buffer_state = Get<BUFFER_STATE>(buffer);
438 if (buffer_state) {
439 WriteLockGuard guard(buffer_address_lock_);
440 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
441 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600442 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600443}
444
445void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
446 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600447 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600448}
449
450void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
451 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600452 if (disabled[command_buffer_state]) return;
453
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700454 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600455 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600456}
457
458void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
459 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
460 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600461 if (disabled[command_buffer_state]) return;
462
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700463 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600464
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600465 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600466}
467
Jeff Leger178b1e52020-10-05 12:22:23 -0400468void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
469 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600470 if (disabled[command_buffer_state]) return;
471
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700472 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600473 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
474 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400475}
476
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700477void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
478 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
479 if (disabled[command_buffer_state]) return;
480
481 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
482 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
483 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
484}
485
locke-lunargd556cc32019-09-17 01:21:23 -0600486void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
487 VkImageLayout dstImageLayout, uint32_t regionCount,
488 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600489 if (disabled[command_buffer_state]) return;
490
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700491 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600492 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600493}
494
Jeff Leger178b1e52020-10-05 12:22:23 -0400495void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
496 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600497 if (disabled[command_buffer_state]) return;
498
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700499 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600500 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
501 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400502}
503
Tony Barbour845d29b2021-11-09 11:43:14 -0700504void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
505 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
506 if (disabled[command_buffer_state]) return;
507
508 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
509 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
510 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
511}
512
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700513// Gets union of all features defined by Potential Format Features
514// 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 +0200515VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
516 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700517
518 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200519 if (has_format_feature2) {
520 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200521 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
522 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200523 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100524
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200525 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100526
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200527 format_features |= fmt_props_3.linearTilingFeatures;
528 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100529
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200530 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
531 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
532 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
533 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
534 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100535
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200536 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
537 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
538 }
539 }
540 } else {
541 VkFormatProperties format_properties;
542 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
543 format_features |= format_properties.linearTilingFeatures;
544 format_features |= format_properties.optimalTilingFeatures;
545
546 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
547 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
548 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
549
550 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
551
552 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
553 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
554 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
555 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
556
557 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
558 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
559 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700560 }
561 }
562 }
563
564 return format_features;
565}
566
locke-lunargd556cc32019-09-17 01:21:23 -0600567void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
568 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
569 VkResult result) {
570 if (VK_SUCCESS != result) return;
571
Locke Linf3873542021-04-26 11:25:10 -0600572 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
573 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
574 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
575
locke-lunargd556cc32019-09-17 01:21:23 -0600576 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
577 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700578 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600579 if (features2) {
580 enabled_features_found = &(features2->features);
581 }
582 }
583
locke-lunargd556cc32019-09-17 01:21:23 -0600584 if (nullptr == enabled_features_found) {
585 state_tracker->enabled_features.core = {};
586 } else {
587 state_tracker->enabled_features.core = *enabled_features_found;
588 }
589
locke-lunargd556cc32019-09-17 01:21:23 -0600590 // Save local link to this device's physical device state
Jeremy Gebben9f537102021-10-05 16:37:12 -0600591 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
locke-lunargd556cc32019-09-17 01:21:23 -0600592
Tony-LunarG273f32f2021-09-28 08:56:30 -0600593 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
594 if (vulkan_13_features) {
595 state_tracker->enabled_features.core13 = *vulkan_13_features;
596 } else {
597 state_tracker->enabled_features.core13 = {};
598 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
599 if (image_robustness_features) {
600 state_tracker->enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
601 }
602
603 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
604 if (inline_uniform_block_features) {
605 state_tracker->enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
606 state_tracker->enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
607 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
608 }
609
610 const auto *pipeline_creation_cache_control_features =
611 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
612 if (pipeline_creation_cache_control_features) {
613 state_tracker->enabled_features.core13.pipelineCreationCacheControl =
614 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
615 }
616
617 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
618 if (private_data_features) {
619 state_tracker->enabled_features.core13.privateData = private_data_features->privateData;
620 }
621
622 const auto *demote_to_helper_invocation_features =
623 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
624 if (demote_to_helper_invocation_features) {
625 state_tracker->enabled_features.core13.shaderDemoteToHelperInvocation =
626 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
627 }
628
629 const auto *terminate_invocation_features =
630 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
631 if (terminate_invocation_features) {
632 state_tracker->enabled_features.core13.shaderTerminateInvocation =
633 terminate_invocation_features->shaderTerminateInvocation;
634 }
635
636 const auto *subgroup_size_control_features =
637 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
638 if (subgroup_size_control_features) {
639 state_tracker->enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
640 state_tracker->enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
641 }
642
643 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
644 if (synchronization2_features) {
645 state_tracker->enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
646 }
647
648 const auto *texture_compression_astchdr_features =
649 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
650 if (texture_compression_astchdr_features) {
651 state_tracker->enabled_features.core13.textureCompressionASTC_HDR =
652 texture_compression_astchdr_features->textureCompressionASTC_HDR;
653 }
654
655 const auto *initialize_workgroup_memory_features =
656 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
657 if (initialize_workgroup_memory_features) {
658 state_tracker->enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
659 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
660 }
661
662 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
663 if (dynamic_rendering_features) {
664 state_tracker->enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
665 }
666
667 const auto *shader_integer_dot_product_features =
668 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
669 if (shader_integer_dot_product_features) {
670 state_tracker->enabled_features.core13.shaderIntegerDotProduct =
671 shader_integer_dot_product_features->shaderIntegerDotProduct;
672 }
673
674 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
675 if (maintenance4_features) {
676 state_tracker->enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
677 }
678 }
679
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700680 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700681 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700682 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700683 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700684 // Set Extension Feature Aliases to false as there is no struct to check
685 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
686 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
687 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
688 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
689 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
690 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800691 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700692
693 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700694
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700695 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700696 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700697 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
698 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
699 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
700 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700701 }
702
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700703 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700704 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700705 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
706 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700707 }
708
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700709 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700710 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700711 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
712 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
713 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
714 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
715 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
716 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
717 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
718 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
719 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
720 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
721 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
722 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
723 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
724 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
725 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
726 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
727 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
728 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
729 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
730 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
731 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
732 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
733 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
734 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
735 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
736 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
737 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
738 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
739 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
740 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
741 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
742 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
743 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
744 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
745 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
746 descriptor_indexing_features->descriptorBindingPartiallyBound;
747 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
748 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
749 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700750 }
751
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700752 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700753 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700754 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700755 }
756
757 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700758 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700760 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700761 }
762
763 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700764 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700766 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
767 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700768 }
769
770 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700771 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700772 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700773 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
774 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700775 }
776
777 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700778 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700779 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700780 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
781 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700782 }
783
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700784 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700785 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700786 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700787 }
788
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700789 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700790 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700791 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700792 }
793
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700794 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700795 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700796 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
797 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
798 buffer_device_address->bufferDeviceAddressCaptureReplay;
799 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
800 buffer_device_address->bufferDeviceAddressMultiDevice;
801 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800802
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700803 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800804 if (atomic_int64_features) {
805 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
806 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
807 }
808
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700809 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800810 if (memory_model_features) {
811 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
812 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
813 memory_model_features->vulkanMemoryModelDeviceScope;
814 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
815 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
816 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700817 }
818
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700819 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820 if (vulkan_11_features) {
821 state_tracker->enabled_features.core11 = *vulkan_11_features;
822 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700823 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700824
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700825 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700826 if (sixteen_bit_storage_features) {
827 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
828 sixteen_bit_storage_features->storageBuffer16BitAccess;
829 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
830 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
831 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
832 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
833 }
834
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700835 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700836 if (multiview_features) {
837 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
838 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
839 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
840 }
841
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700842 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700843 if (variable_pointers_features) {
844 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
845 variable_pointers_features->variablePointersStorageBuffer;
846 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
847 }
848
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700849 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700850 if (protected_memory_features) {
851 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
852 }
853
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700854 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 if (ycbcr_conversion_features) {
856 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
857 }
858
859 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700860 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700861 if (shader_draw_parameters_features) {
862 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700863 }
864 }
865
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700866 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600867 if (device_group_ci) {
868 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
869 state_tracker->device_group_create_info = *device_group_ci;
870 } else {
871 state_tracker->physical_device_count = 1;
872 }
locke-lunargd556cc32019-09-17 01:21:23 -0600873
sfricke-samsung828e59d2021-08-22 23:20:49 -0700874 // Features from other extensions passesd in create info
875 {
876 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
877 if (exclusive_scissor_features) {
878 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
879 }
locke-lunargd556cc32019-09-17 01:21:23 -0600880
sfricke-samsung828e59d2021-08-22 23:20:49 -0700881 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
882 if (shading_rate_image_features) {
883 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
884 }
locke-lunargd556cc32019-09-17 01:21:23 -0600885
sfricke-samsung828e59d2021-08-22 23:20:49 -0700886 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
887 if (mesh_shader_features) {
888 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
889 }
locke-lunargd556cc32019-09-17 01:21:23 -0600890
sfricke-samsung828e59d2021-08-22 23:20:49 -0700891 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
892 if (transform_feedback_features) {
893 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
894 }
locke-lunargd556cc32019-09-17 01:21:23 -0600895
sfricke-samsung828e59d2021-08-22 23:20:49 -0700896 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
897 if (vtx_attrib_div_features) {
898 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
899 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700900
sfricke-samsung828e59d2021-08-22 23:20:49 -0700901 const auto *buffer_device_address_ext_features =
902 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
903 if (buffer_device_address_ext_features) {
904 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
905 }
locke-lunargd556cc32019-09-17 01:21:23 -0600906
sfricke-samsung828e59d2021-08-22 23:20:49 -0700907 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
908 if (cooperative_matrix_features) {
909 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
910 }
locke-lunargd556cc32019-09-17 01:21:23 -0600911
sfricke-samsung828e59d2021-08-22 23:20:49 -0700912 const auto *compute_shader_derivatives_features =
913 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
914 if (compute_shader_derivatives_features) {
915 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *fragment_shader_barycentric_features =
919 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
920 if (fragment_shader_barycentric_features) {
921 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
922 }
locke-lunargd556cc32019-09-17 01:21:23 -0600923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *shader_image_footprint_features =
925 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
926 if (shader_image_footprint_features) {
927 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
928 }
locke-lunargd556cc32019-09-17 01:21:23 -0600929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *fragment_shader_interlock_features =
931 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
932 if (fragment_shader_interlock_features) {
933 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
934 }
locke-lunargd556cc32019-09-17 01:21:23 -0600935
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 const auto *texel_buffer_alignment_features =
937 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
938 if (texel_buffer_alignment_features) {
939 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *pipeline_exe_props_features =
943 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
944 if (pipeline_exe_props_features) {
945 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
946 }
locke-lunargd556cc32019-09-17 01:21:23 -0600947
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 const auto *dedicated_allocation_image_aliasing_features =
949 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
950 if (dedicated_allocation_image_aliasing_features) {
951 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
952 *dedicated_allocation_image_aliasing_features;
953 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500954
sfricke-samsung828e59d2021-08-22 23:20:49 -0700955 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
956 if (performance_query_features) {
957 state_tracker->enabled_features.performance_query_features = *performance_query_features;
958 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100959
sfricke-samsung828e59d2021-08-22 23:20:49 -0700960 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
961 if (device_coherent_memory_features) {
962 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
963 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000964
sfricke-samsung828e59d2021-08-22 23:20:49 -0700965 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
966 if (ycbcr_image_array_features) {
967 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
968 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800969
sfricke-samsung828e59d2021-08-22 23:20:49 -0700970 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
971 if (ray_query_features) {
972 state_tracker->enabled_features.ray_query_features = *ray_query_features;
973 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700974
sfricke-samsung828e59d2021-08-22 23:20:49 -0700975 const auto *ray_tracing_pipeline_features =
976 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
977 if (ray_tracing_pipeline_features) {
978 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
979 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700980
sfricke-samsung828e59d2021-08-22 23:20:49 -0700981 const auto *ray_tracing_acceleration_structure_features =
982 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
983 if (ray_tracing_acceleration_structure_features) {
984 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
985 *ray_tracing_acceleration_structure_features;
986 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500987
sfricke-samsung828e59d2021-08-22 23:20:49 -0700988 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
989 if (robustness2_features) {
990 state_tracker->enabled_features.robustness2_features = *robustness2_features;
991 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500992
sfricke-samsung828e59d2021-08-22 23:20:49 -0700993 const auto *fragment_density_map_features =
994 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
995 if (fragment_density_map_features) {
996 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
997 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200998
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 const auto *fragment_density_map_features2 =
1000 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1001 if (fragment_density_map_features2) {
1002 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
1003 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001004
Agarwal, Arpit78509112022-02-17 15:29:05 -07001005 const auto *fragment_density_map_offset_features =
1006 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1007 if (fragment_density_map_offset_features) {
1008 state_tracker->enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
1009 }
1010
sfricke-samsung828e59d2021-08-22 23:20:49 -07001011 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1012 if (astc_decode_features) {
1013 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
1014 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001015
sfricke-samsung828e59d2021-08-22 23:20:49 -07001016 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1017 if (custom_border_color_features) {
1018 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
1019 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001020
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 const auto *fragment_shading_rate_features =
1022 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1023 if (fragment_shading_rate_features) {
1024 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
1025 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001026
sfricke-samsung828e59d2021-08-22 23:20:49 -07001027 const auto *extended_dynamic_state_features =
1028 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1029 if (extended_dynamic_state_features) {
1030 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
1031 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001032
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 const auto *extended_dynamic_state2_features =
1034 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1035 if (extended_dynamic_state2_features) {
1036 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
1037 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001038
sfricke-samsung828e59d2021-08-22 23:20:49 -07001039 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1040 if (multiview_features) {
1041 state_tracker->enabled_features.multiview_features = *multiview_features;
1042 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001043
sfricke-samsung828e59d2021-08-22 23:20:49 -07001044 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1045 if (portability_features) {
1046 state_tracker->enabled_features.portability_subset_features = *portability_features;
1047 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001048
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 const auto *shader_integer_functions2_features =
1050 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1051 if (shader_integer_functions2_features) {
1052 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1053 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001054
sfricke-samsung828e59d2021-08-22 23:20:49 -07001055 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1056 if (shader_sm_builtins_features) {
1057 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
1058 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001059
sfricke-samsung828e59d2021-08-22 23:20:49 -07001060 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1061 if (shader_atomic_float_features) {
1062 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
1063 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001064
sfricke-samsung828e59d2021-08-22 23:20:49 -07001065 const auto *shader_image_atomic_int64_features =
1066 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1067 if (shader_image_atomic_int64_features) {
1068 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1069 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001070
sfricke-samsung828e59d2021-08-22 23:20:49 -07001071 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1072 if (shader_clock_features) {
1073 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1074 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001075
sfricke-samsung828e59d2021-08-22 23:20:49 -07001076 const auto *conditional_rendering_features =
1077 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1078 if (conditional_rendering_features) {
1079 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1080 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001081
sfricke-samsung828e59d2021-08-22 23:20:49 -07001082 const auto *workgroup_memory_explicit_layout_features =
1083 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1084 if (workgroup_memory_explicit_layout_features) {
1085 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1086 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001087
sfricke-samsung828e59d2021-08-22 23:20:49 -07001088 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1089 if (provoking_vertex_features) {
1090 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1091 }
Locke Linf3873542021-04-26 11:25:10 -06001092
sfricke-samsung828e59d2021-08-22 23:20:49 -07001093 const auto *vertex_input_dynamic_state_features =
1094 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1095 if (vertex_input_dynamic_state_features) {
1096 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1097 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001098
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 const auto *inherited_viewport_scissor_features =
1100 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1101 if (inherited_viewport_scissor_features) {
1102 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1103 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001104
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1106 if (multi_draw_features) {
1107 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1108 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001109
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1111 if (color_write_features) {
1112 state_tracker->enabled_features.color_write_features = *color_write_features;
1113 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001114
sfricke-samsung828e59d2021-08-22 23:20:49 -07001115 const auto *shader_atomic_float2_features =
1116 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1117 if (shader_atomic_float2_features) {
1118 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1119 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001120
sfricke-samsung828e59d2021-08-22 23:20:49 -07001121 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1122 if (present_id_features) {
1123 state_tracker->enabled_features.present_id_features = *present_id_features;
1124 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001125
sfricke-samsung828e59d2021-08-22 23:20:49 -07001126 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1127 if (present_wait_features) {
1128 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1129 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001130
1131 const auto *ray_tracing_motion_blur_features =
1132 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1133 if (ray_tracing_motion_blur_features) {
1134 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1135 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001136
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001137 const auto *primitive_topology_list_restart_features =
1138 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1139 if (primitive_topology_list_restart_features) {
1140 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1141 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001142
ziga-lunarge1988962021-09-16 13:32:34 +02001143 const auto *zero_initialize_work_group_memory_features =
1144 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1145 if (zero_initialize_work_group_memory_features) {
1146 state_tracker->enabled_features.zero_initialize_work_group_memory_features =
1147 *zero_initialize_work_group_memory_features;
1148 }
1149
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001150 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1151 if (rgba10x6_formats_features) {
1152 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
1153 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001154
Tony-LunarG69604c42021-11-22 16:00:12 -07001155 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1156 if (image_view_min_lod_features) {
1157 state_tracker->enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
1158 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001159 }
1160
locke-lunargd556cc32019-09-17 01:21:23 -06001161 // Store physical device properties and physical device mem limits into CoreChecks structs
1162 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1163 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1164
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001165 {
1166 uint32_t n_props = 0;
1167 std::vector<VkExtensionProperties> props;
1168 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, NULL);
1169 props.resize(n_props);
Tony-LunarG8c380b92022-01-12 13:44:04 -07001170 instance_dispatch_table.EnumerateDeviceExtensionProperties(gpu, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001171
1172 for (const auto &ext_prop : props) {
1173 state_tracker->phys_dev_extensions.insert(ext_prop.extensionName);
1174 }
1175
1176 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1177 // a path to grab that information from the physical device. This
1178 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1179 // Vulkan 1.1 (which made this core).
1180 state_tracker->has_format_feature2 =
1181 (state_tracker->api_version >= VK_API_VERSION_1_1 ||
1182 IsExtEnabled(state_tracker->instance_extensions.vk_khr_get_physical_device_properties2)) &&
1183 state_tracker->phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) !=
1184 state_tracker->phys_dev_extensions.end();
1185 }
1186
locke-lunargd556cc32019-09-17 01:21:23 -06001187 const auto &dev_ext = state_tracker->device_extensions;
1188 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1189
Tony-LunarG273f32f2021-09-28 08:56:30 -06001190 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1191 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
sfricke-samsung45996a42021-09-16 13:45:27 -07001192 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
1193 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001194 if (dev_ext.vk_feature_version_1_3)
1195 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_3, &state_tracker->phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001196 } else {
1197 // VkPhysicalDeviceVulkan11Properties
1198 //
1199 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1200
1201 if (dev_ext.vk_khr_multiview) {
1202 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1203 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1204 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1205 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1206 }
1207
1208 if (dev_ext.vk_khr_maintenance3) {
1209 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1210 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1211 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1212 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1213 }
1214
1215 // Some 1.1 properties were added to core without previous extensions
1216 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1217 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1218 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1219 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1220 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1221
1222 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1223 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1224 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1225 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1226
1227 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1228 }
1229
1230 // VkPhysicalDeviceVulkan12Properties
1231 //
1232 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1233
1234 if (dev_ext.vk_ext_descriptor_indexing) {
1235 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1236 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1237 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1238 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1239 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1240 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1241 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1242 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1243 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1244 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1245 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1246 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1247 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1248 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1249 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1250 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1251 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1252 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1253 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1254 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1255 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1256 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1257 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1258 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1259 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1260 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1261 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1262 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1263 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1264 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1265 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1266 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1267 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1268 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1269 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1270 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1271 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1272 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1273 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1274 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1275 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1276 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1277 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1278 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1279 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1280 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1281 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1282 }
1283
1284 if (dev_ext.vk_khr_depth_stencil_resolve) {
1285 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1286 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1287 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1288 depth_stencil_resolve_props.supportedDepthResolveModes;
1289 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1290 depth_stencil_resolve_props.supportedStencilResolveModes;
1291 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1292 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1293 }
1294
1295 if (dev_ext.vk_khr_timeline_semaphore) {
1296 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1297 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1298 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1299 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1300 }
1301
1302 if (dev_ext.vk_ext_sampler_filter_minmax) {
1303 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1304 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1305 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1306 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1307 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1308 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1309 }
1310
1311 if (dev_ext.vk_khr_shader_float_controls) {
1312 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1313 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1314 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1315 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1316 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1317 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1318 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1319 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1320 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1321 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1322 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1323 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1324 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1325 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1326 float_controls_props.shaderDenormFlushToZeroFloat16;
1327 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1328 float_controls_props.shaderDenormFlushToZeroFloat32;
1329 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1330 float_controls_props.shaderDenormFlushToZeroFloat64;
1331 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1332 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1333 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1334 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1335 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1336 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1337 }
locke-lunargd556cc32019-09-17 01:21:23 -06001338 }
1339
sfricke-samsung828e59d2021-08-22 23:20:49 -07001340 // Extensions with properties to extract to DeviceExtensionProperties
1341 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001342 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1343 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1344 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1345 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001346 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001347 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001348 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1349 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001350 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1351 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001352 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Agarwal, Arpit78509112022-02-17 15:29:05 -07001353 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_qcom_fragment_density_map_offset,
1354 &phys_dev_props->fragment_density_map_offset_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001355 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001356 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001357 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001358 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001359 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001360 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001361 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001362 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001363 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001364 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001365 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001366 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001367
sfricke-samsung45996a42021-09-16 13:45:27 -07001368 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001369 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001370 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1371 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001372 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1373 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1374
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001375 uint32_t num_cooperative_matrix_properties = 0;
1376 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1377 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001378 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001379
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001380 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001381 state_tracker->cooperative_matrix_properties.data());
1382 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001383
locke-lunargd556cc32019-09-17 01:21:23 -06001384 // Store queue family data
1385 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1386 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001387 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001388 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1389 state_tracker->device_queue_info_list.push_back(
1390 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001391 }
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001392 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1393 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1394 VkQueue queue = VK_NULL_HANDLE;
1395 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1396 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1397 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1398 get_info.flags = queue_info.flags;
1399 get_info.queueFamilyIndex = queue_info.queue_family_index;
1400 get_info.queueIndex = i;
1401 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1402 } else {
1403 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1404 }
1405 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001406 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001407 }
locke-lunargd556cc32019-09-17 01:21:23 -06001408 }
1409 }
1410}
1411
1412void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1413 if (!device) return;
1414
Jeremy Gebbend177d922021-10-28 13:42:10 -06001415 command_pool_map_.clear();
1416 assert(command_buffer_map_.empty());
1417 pipeline_map_.clear();
1418 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001419
1420 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001421 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001422 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001423 assert(descriptor_set_map_.empty());
1424 desc_template_map_.clear();
1425 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001426 // Because swapchains are associated with Surfaces, which are at instance level,
1427 // they need to be explicitly destroyed here to avoid continued references to
1428 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001429 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001430 entry.second->Destroy();
1431 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001432 swapchain_map_.clear();
1433 image_view_map_.clear();
1434 image_map_.clear();
1435 buffer_view_map_.clear();
1436 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001437 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001438 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001439}
1440
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001441void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1442 VkFence fence, VkResult result) {
1443 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001444 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001445
Jeremy Gebben57642982021-09-14 14:14:55 -06001446 uint64_t early_retire_seq = 0;
1447
1448 if (submitCount == 0) {
1449 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001450 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001451 early_retire_seq = queue_state->Submit(std::move(submission));
1452 }
locke-lunargd556cc32019-09-17 01:21:23 -06001453
1454 // Now process each individual submit
1455 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001456 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001457 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001458 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001459 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001460 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001461 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1462 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1463 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1464 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001465 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001466 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001467
locke-lunargd556cc32019-09-17 01:21:23 -06001468 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001469 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001470 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1471 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1472 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1473 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001474 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001475 }
1476
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001477 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001478 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001479
locke-lunargd556cc32019-09-17 01:21:23 -06001480 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001481 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001482 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001483 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001484 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001485 }
1486 auto submit_seq = queue_state->Submit(std::move(submission));
1487 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001488 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001489
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001490 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001491 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001492 }
1493}
1494
Tony-LunarG26fe2842021-11-16 14:07:59 -07001495void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1496 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001497 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001498 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001499 uint64_t early_retire_seq = 0;
1500 if (submitCount == 0) {
1501 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001502 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001503 early_retire_seq = queue_state->Submit(std::move(submission));
1504 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001505
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001506 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1507 CB_SUBMISSION submission;
1508 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001509 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1510 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001511 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001512 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001513 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1514 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001515 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001516 }
1517 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1518 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1519
1520 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001521 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001522 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001523 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001524 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001525 }
1526 auto submit_seq = queue_state->Submit(std::move(submission));
1527 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001528 }
locke-lunargd556cc32019-09-17 01:21:23 -06001529 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001530 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001531 }
1532}
1533
Tony-LunarG26fe2842021-11-16 14:07:59 -07001534void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1535 VkFence fence, VkResult result) {
1536 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1537}
1538
1539void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1540 VkFence fence, VkResult result) {
1541 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1542}
1543
locke-lunargd556cc32019-09-17 01:21:23 -06001544void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1545 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1546 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001547 if (VK_SUCCESS != result) {
1548 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001549 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001550 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1551 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1552 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1553
1554 layer_data::optional<DedicatedBinding> dedicated_binding;
1555
1556 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1557 if (dedicated) {
1558 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001559 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001560 assert(buffer_state);
1561 if (!buffer_state) {
1562 return;
1563 }
1564 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1565 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001566 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001567 assert(image_state);
1568 if (!image_state) {
1569 return;
1570 }
1571 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1572 }
1573 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001574 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1575 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001576 return;
1577}
1578
1579void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001580 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001581 if (mem_info) {
1582 fake_memory.Free(mem_info->fake_base_address);
1583 }
1584 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001585}
1586
1587void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1588 VkFence fence, VkResult result) {
1589 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001590 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001591
Jeremy Gebben57642982021-09-14 14:14:55 -06001592 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001593
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001594 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1595 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001596 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001597 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1598 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1599 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001600 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001601 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001602 if (buffer_state && mem_state) {
1603 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1604 }
locke-lunargd556cc32019-09-17 01:21:23 -06001605 }
1606 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001607 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1608 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1609 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001610 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001611 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001612 if (image_state && mem_state) {
1613 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1614 }
locke-lunargd556cc32019-09-17 01:21:23 -06001615 }
1616 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001617 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1618 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1619 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001620 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1621 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001622 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001623 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001624 if (image_state && mem_state) {
1625 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1626 }
locke-lunargd556cc32019-09-17 01:21:23 -06001627 }
1628 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001629 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001630 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001631 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001632 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001633 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001634 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001635 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001636 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001637 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001639 auto submit_seq = queue_state->Submit(std::move(submission));
1640 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001641 }
1642
1643 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001644 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001645 }
1646}
1647
1648void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1649 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1650 VkResult result) {
1651 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001652 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001653}
1654
Mike Schuchardt2df08912020-12-15 16:28:09 -08001655void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1656 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001657 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1658 if (semaphore_state) {
1659 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001660 }
1661}
1662
Mike Schuchardt2df08912020-12-15 16:28:09 -08001663void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001664 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001665 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001666 if (semaphore_state) {
1667 semaphore_state->RetireTimeline(pSignalInfo->value);
1668 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001669}
1670
locke-lunargd556cc32019-09-17 01:21:23 -06001671void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001672 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001673 if (mem_info) {
1674 mem_info->mapped_range.offset = offset;
1675 mem_info->mapped_range.size = size;
1676 mem_info->p_driver_data = *ppData;
1677 }
1678}
1679
locke-lunargd556cc32019-09-17 01:21:23 -06001680void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1681 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1682 if (VK_SUCCESS != result) return;
1683
1684 // When we know that all fences are complete we can clean/remove their CBs
1685 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1686 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001687 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001688 if (fence_state) {
1689 fence_state->Retire();
1690 }
locke-lunargd556cc32019-09-17 01:21:23 -06001691 }
1692 }
1693 // NOTE : Alternate case not handled here is when some fences have completed. In
1694 // this case for app to guarantee which fences completed it will have to call
1695 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1696}
1697
John Zulauff89de662020-04-13 18:57:34 -06001698void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1699 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001700 if (VK_SUCCESS != result) return;
1701
Jeremy Gebben15332642021-12-15 19:33:15 -07001702 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1703 // the application calls vkGetSemaphoreCounterValue() on each of them.
1704 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1705 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1706 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1707 if (semaphore_state) {
1708 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1709 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001710 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001711 }
1712}
1713
John Zulauff89de662020-04-13 18:57:34 -06001714void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1715 VkResult result) {
1716 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1717}
1718
1719void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1720 uint64_t timeout, VkResult result) {
1721 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1722}
1723
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001724void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1725 VkResult result) {
1726 if (VK_SUCCESS != result) return;
1727
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001728 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001729 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001730 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001731 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001732}
1733
1734void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1735 VkResult result) {
1736 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1737}
1738void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1739 VkResult result) {
1740 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1741}
1742
locke-lunargd556cc32019-09-17 01:21:23 -06001743void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1744 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001745 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001746 if (fence_state) {
1747 fence_state->Retire();
1748 }
locke-lunargd556cc32019-09-17 01:21:23 -06001749}
1750
Yilong Lice03a312022-01-02 02:08:35 -08001751void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1752 if (Get<QUEUE_STATE>(queue) == nullptr) {
1753 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1754 }
1755}
1756
1757void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1758 VkQueue *pQueue) {
1759 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1760}
1761
1762void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1763 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1764}
1765
locke-lunargd556cc32019-09-17 01:21:23 -06001766void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1767 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001768 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001769 if (queue_state) {
1770 queue_state->Retire();
1771 }
locke-lunargd556cc32019-09-17 01:21:23 -06001772}
1773
1774void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1775 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001776 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001777 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001778 }
1779}
1780
1781void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001782 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001783}
1784
1785void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1786 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001787 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001788}
1789
1790void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001791 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001792}
1793
1794void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1795 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001796 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001797}
1798
locke-lunargd556cc32019-09-17 01:21:23 -06001799void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001800 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001801 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001802 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001803 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001804 if (mem_state) {
1805 buffer_state->SetMemBinding(mem_state, memoryOffset);
1806 }
locke-lunargd556cc32019-09-17 01:21:23 -06001807 }
1808}
1809
1810void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1811 VkDeviceSize memoryOffset, VkResult result) {
1812 if (VK_SUCCESS != result) return;
1813 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1814}
1815
1816void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001817 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001818 for (uint32_t i = 0; i < bindInfoCount; i++) {
1819 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1820 }
1821}
1822
1823void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001824 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001825 for (uint32_t i = 0; i < bindInfoCount; i++) {
1826 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1827 }
1828}
1829
Spencer Fricke6c127102020-04-16 06:25:20 -07001830void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001831 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001832 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001833 buffer_state->memory_requirements_checked = true;
1834 }
1835}
1836
1837void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1838 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001839 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001840}
1841
1842void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(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
1848void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001849 const VkBufferMemoryRequirementsInfo2 *pInfo,
1850 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001851 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001852}
1853
Spencer Fricke6c127102020-04-16 06:25:20 -07001854void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001855 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001856 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001857 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001858 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001859 if (plane_info != nullptr) {
1860 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001861 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001862 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001863 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001864 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001865 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001866 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001867 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001868 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001869 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001870 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001871 }
locke-lunargd556cc32019-09-17 01:21:23 -06001872 }
1873}
1874
1875void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1876 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001877 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001878}
1879
1880void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, 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
1885void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1886 const VkImageMemoryRequirementsInfo2 *pInfo,
1887 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001888 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001889}
1890
locke-lunargd556cc32019-09-17 01:21:23 -06001891void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1892 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1893 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001894 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001895 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001896}
1897
1898void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001899 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1900 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001901 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001902 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001903}
1904
1905void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001906 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1907 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001908 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001909 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001910}
1911
1912void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1913 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001914 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001915}
1916
1917void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1918 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001919 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001920}
1921
1922void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1923 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001924 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001925}
1926
1927void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1928 const VkAllocationCallbacks *pAllocator) {
1929 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001930 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001931 // Any bound cmd buffers are now invalid
1932 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001933 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1934 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1935 custom_border_color_sampler_count--;
1936 }
locke-lunargd556cc32019-09-17 01:21:23 -06001937 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001938 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001939}
1940
1941void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1942 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001943 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001944}
1945
1946void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1947 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001948 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001949}
1950
locke-lunargd556cc32019-09-17 01:21:23 -06001951void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1952 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001953 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1954 if (pool) {
1955 pool->Free(commandBufferCount, pCommandBuffers);
1956 }
locke-lunargd556cc32019-09-17 01:21:23 -06001957}
1958
1959void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1960 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1961 VkResult result) {
1962 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001963 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001964 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001965}
1966
1967void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1968 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1969 VkResult result) {
1970 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001971
1972 uint32_t index_count = 0, n_perf_pass = 0;
1973 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001974 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001975 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001976 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001977
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001978 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001979 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1980 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1981 switch (counter.scope) {
1982 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001983 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001984 break;
1985 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001986 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001987 break;
1988 default:
1989 break;
1990 }
1991 }
1992
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001993 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001994 }
1995
Jeremy Gebben082a9832021-10-28 13:40:11 -06001996 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 -06001997
locke-lunargd556cc32019-09-17 01:21:23 -06001998}
1999
2000void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2001 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002002 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002003}
2004
2005void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2006 VkCommandPoolResetFlags flags, VkResult result) {
2007 if (VK_SUCCESS != result) return;
2008 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002009 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2010 if (pool) {
2011 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002012 }
2013}
2014
2015void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2016 VkResult result) {
2017 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002018 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002019 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002020 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002021 }
2022 }
2023}
2024
locke-lunargd556cc32019-09-17 01:21:23 -06002025void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2026 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002027 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002028}
2029
2030void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2031 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002032 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002033}
2034
2035void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2036 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2037 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2042 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2043 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002044 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002045 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2046 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2047 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2048 cgpl_state->pipe_state.reserve(count);
2049 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002050 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002051 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
2052 Get<RENDER_PASS_STATE>(pCreateInfos[i].renderPass),
2053 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Tony-LunarG273f32f2021-09-28 08:56:30 -06002054 } else if (enabled_features.core13.dynamicRendering) {
Tony-LunarG40b33882021-12-02 12:40:11 -07002055 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(pCreateInfos[i].pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002056 cgpl_state->pipe_state.push_back(
2057 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], std::make_shared<RENDER_PASS_STATE>(dynamic_rendering),
Jeremy Gebben9f537102021-10-05 16:37:12 -06002058 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002059 }
locke-lunargd556cc32019-09-17 01:21:23 -06002060 }
2061 return false;
2062}
2063
2064void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2065 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2066 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2067 VkResult result, void *cgpl_state_data) {
2068 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2069 // This API may create pipelines regardless of the return value
2070 for (uint32_t i = 0; i < count; i++) {
2071 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002072 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002073 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002074 }
2075 }
2076 cgpl_state->pipe_state.clear();
2077}
2078
2079bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2080 const VkComputePipelineCreateInfo *pCreateInfos,
2081 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002082 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002083 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2084 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2085 ccpl_state->pipe_state.reserve(count);
2086 for (uint32_t i = 0; i < count; i++) {
2087 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002088 ccpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002089 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002090 }
2091 return false;
2092}
2093
2094void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2095 const VkComputePipelineCreateInfo *pCreateInfos,
2096 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2097 VkResult result, void *ccpl_state_data) {
2098 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2099
2100 // This API may create pipelines regardless of the return value
2101 for (uint32_t i = 0; i < count; i++) {
2102 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002103 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002104 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002105 }
2106 }
2107 ccpl_state->pipe_state.clear();
2108}
2109
2110bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2111 uint32_t count,
2112 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2113 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002114 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002115 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2116 crtpl_state->pipe_state.reserve(count);
2117 for (uint32_t i = 0; i < count; i++) {
2118 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002119 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002120 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002121 }
2122 return false;
2123}
2124
2125void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2126 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2127 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2128 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2129 // This API may create pipelines regardless of the return value
2130 for (uint32_t i = 0; i < count; i++) {
2131 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002132 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002133 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002134 }
2135 }
2136 crtpl_state->pipe_state.clear();
2137}
2138
sourav parmarcd5fb182020-07-17 12:58:44 -07002139bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2140 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002141 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2142 const VkAllocationCallbacks *pAllocator,
2143 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002144 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002145 crtpl_state->pipe_state.reserve(count);
2146 for (uint32_t i = 0; i < count; i++) {
2147 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002148 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06002149 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002150 }
2151 return false;
2152}
2153
sourav parmarcd5fb182020-07-17 12:58:44 -07002154void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2155 VkPipelineCache pipelineCache, uint32_t count,
2156 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2157 const VkAllocationCallbacks *pAllocator,
2158 VkPipeline *pPipelines, VkResult result,
2159 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002160 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2161 // This API may create pipelines regardless of the return value
2162 for (uint32_t i = 0; i < count; i++) {
2163 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002164 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002165 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002166 }
2167 }
2168 crtpl_state->pipe_state.clear();
2169}
2170
locke-lunargd556cc32019-09-17 01:21:23 -06002171void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2172 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2173 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002174 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002175 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2176 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002177 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002178 }
locke-lunargd556cc32019-09-17 01:21:23 -06002179}
2180
2181void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2182 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2183 const VkAllocationCallbacks *pAllocator,
2184 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2185 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002186 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002187}
2188
locke-lunargd556cc32019-09-17 01:21:23 -06002189void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2190 const VkAllocationCallbacks *pAllocator,
2191 VkPipelineLayout *pPipelineLayout, VkResult result) {
2192 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002193 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002194}
2195
2196void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2197 const VkAllocationCallbacks *pAllocator,
2198 VkDescriptorPool *pDescriptorPool, VkResult result) {
2199 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002200 Add(std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002201}
2202
2203void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2204 VkDescriptorPoolResetFlags flags, VkResult result) {
2205 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002206 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2207 if (pool) {
2208 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002209 }
locke-lunargd556cc32019-09-17 01:21:23 -06002210}
2211
2212bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2213 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002214 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002215 // Always update common data
2216 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2217 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2218 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2219
2220 return false;
2221}
2222
2223// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2224void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2225 VkDescriptorSet *pDescriptorSets, VkResult result,
2226 void *ads_state_data) {
2227 if (VK_SUCCESS != result) return;
2228 // All the updates are contained in a single cvdescriptorset function
2229 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2230 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002231 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2232 if (pool_state) {
2233 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2234 }
locke-lunargd556cc32019-09-17 01:21:23 -06002235}
2236
2237void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2238 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002239 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2240 if (pool_state) {
2241 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002242 }
2243}
2244
2245void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2246 const VkWriteDescriptorSet *pDescriptorWrites,
2247 uint32_t descriptorCopyCount,
2248 const VkCopyDescriptorSet *pDescriptorCopies) {
2249 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2250 pDescriptorCopies);
2251}
2252
2253void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002254 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002255 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002256 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002257 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002258 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002259 }
2260}
2261
locke-lunargd556cc32019-09-17 01:21:23 -06002262void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2263 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002264 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002265 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002266
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002267 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002268}
2269
2270void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002271 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002272 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002273
2274 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002275}
2276
2277void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2278 VkResult result) {
2279 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002280 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2281 if (cb_state) {
2282 cb_state->Reset();
2283 }
locke-lunargd556cc32019-09-17 01:21:23 -06002284 }
2285}
2286
2287CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2288 // initially assume everything is static state
2289 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2290
2291 if (ds) {
2292 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002293 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002294 }
2295 }
locke-lunargd556cc32019-09-17 01:21:23 -06002296 return flags;
2297}
2298
2299// Validation cache:
2300// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002301
2302void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2303 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002304 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002305 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002306 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002307
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002308 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002309 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002310 const auto &create_info = pipe_state->create_info.graphics;
2311 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2312 const auto *viewport_state = create_info.pViewportState;
2313 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002314 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002315 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002316 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002317 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002318
2319 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002320 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2321 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002322 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002323 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002324 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002325 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002326 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002327 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002328
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002329 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002330 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2331 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2332 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002333 if (!has_dynamic_viewport_count) {
2334 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002335 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002336 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2337 // should become = ~uint32_t(0) if the other interpretation is correct.
2338 }
2339 }
2340 if (!has_dynamic_scissor_count) {
2341 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002342 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002343 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2344 // should become = ~uint32_t(0) if the other interpretation is correct.
2345 }
2346 }
locke-lunargd556cc32019-09-17 01:21:23 -06002347 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002348 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002349 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002350 if (!disabled[command_buffer_state]) {
2351 cb_state->AddChild(pipe_state);
2352 }
locke-lunargd556cc32019-09-17 01:21:23 -06002353}
2354
2355void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2356 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002357 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002358 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002359 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2360 cb_state->viewportMask |= bits;
2361 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002362
2363 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2364 for (size_t i = 0; i < viewportCount; ++i) {
2365 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2366 }
locke-lunargd556cc32019-09-17 01:21:23 -06002367}
2368
2369void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2370 uint32_t exclusiveScissorCount,
2371 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002372 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002373 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002374 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2375 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002376}
2377
2378void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2379 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002380 if (disabled[command_buffer_state]) return;
2381
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002382 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002383 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002384
2385 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002386 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002387 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002388 }
2389}
2390
2391void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2392 uint32_t viewportCount,
2393 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002394 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002395 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002396 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2397 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002398}
2399
2400void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2401 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2402 const VkAllocationCallbacks *pAllocator,
2403 VkAccelerationStructureNV *pAccelerationStructure,
2404 VkResult result) {
2405 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002406 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002407}
2408
Jeff Bolz95176d02020-04-01 00:36:16 -05002409void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2410 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2411 const VkAllocationCallbacks *pAllocator,
2412 VkAccelerationStructureKHR *pAccelerationStructure,
2413 VkResult result) {
2414 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002415 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2416 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002417}
2418
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002419void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2420 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2421 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2422 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2423 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002424 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002425 if (dst_as_state != nullptr) {
2426 dst_as_state->Build(&pInfos[i]);
2427 }
2428 }
2429}
2430
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002431// helper method for device side acceleration structure builds
2432void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2433 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2434 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2435 if (dst_as_state) {
2436 dst_as_state->Build(&info);
2437 }
2438 if (disabled[command_buffer_state]) {
2439 return;
2440 }
2441 if (dst_as_state) {
2442 cb_state.AddChild(dst_as_state);
2443 }
2444 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2445 if (src_as_state) {
2446 cb_state.AddChild(src_as_state);
2447 }
2448 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2449 if (scratch_buffer) {
2450 cb_state.AddChild(scratch_buffer);
2451 }
2452
2453 for (uint32_t i = 0; i < info.geometryCount; i++) {
2454 // only one of pGeometries and ppGeometries can be non-null
2455 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2456 switch (geom.geometryType) {
2457 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2458 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2459 if (vertex_buffer) {
2460 cb_state.AddChild(vertex_buffer);
2461 }
2462 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2463 if (index_buffer) {
2464 cb_state.AddChild(index_buffer);
2465 }
2466 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2467 if (transform_buffer) {
2468 cb_state.AddChild(transform_buffer);
2469 }
2470 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2471 if (motion_data) {
2472 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2473 if (motion_buffer) {
2474 cb_state.AddChild(motion_buffer);
2475 }
2476 }
2477 } break;
2478 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2479 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2480 if (data_buffer) {
2481 cb_state.AddChild(data_buffer);
2482 }
2483 } break;
2484 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2485 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2486 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2487 // easily ensure that's true.
2488 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2489 if (data_buffer) {
2490 cb_state.AddChild(data_buffer);
2491 }
2492 } break;
2493 default:
2494 break;
2495 }
2496 }
2497}
2498
sourav parmarcd5fb182020-07-17 12:58:44 -07002499void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2500 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2501 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002502 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002503 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002504 return;
2505 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002506 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002507 for (uint32_t i = 0; i < infoCount; i++) {
2508 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002509 }
2510 cb_state->hasBuildAccelerationStructureCmd = true;
2511}
2512
2513void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2514 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2515 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2516 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002517 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2518 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002519 return;
2520 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002521 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002522 for (uint32_t i = 0; i < infoCount; i++) {
2523 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002524 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002525 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2526 if (indirect_buffer) {
2527 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002528 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002529 }
2530 }
2531 cb_state->hasBuildAccelerationStructureCmd = true;
2532}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002533
locke-lunargd556cc32019-09-17 01:21:23 -06002534void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002535 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002536 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002537 if (as_state != nullptr) {
2538 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002539 as_state->memory_requirements_checked = true;
2540 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002541 as_state->build_scratch_memory_requirements_checked = true;
2542 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002543 as_state->update_scratch_memory_requirements_checked = true;
2544 }
2545 }
2546}
2547
sourav parmarcd5fb182020-07-17 12:58:44 -07002548void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2549 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002550 if (VK_SUCCESS != result) return;
2551 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002552 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002553
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002554 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002555 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002556 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002557 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002558 if (mem_state) {
2559 as_state->SetMemBinding(mem_state, info.memoryOffset);
2560 }
locke-lunargd556cc32019-09-17 01:21:23 -06002561
2562 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002563 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002564 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002565 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2566 }
2567 }
2568 }
2569}
2570
2571void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2572 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2573 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002574 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2575 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002576 return;
2577 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002578 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002579
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002580 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002581 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002582 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002583 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002584 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002585 }
locke-lunargd556cc32019-09-17 01:21:23 -06002586 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002587 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002588 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002589 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002590 cb_state->AddChild(src_as_state);
2591 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002592 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2593 if (instance_buffer) {
2594 cb_state->AddChild(instance_buffer);
2595 }
2596 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2597 if (scratch_buffer) {
2598 cb_state->AddChild(scratch_buffer);
2599 }
2600
2601 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2602 const auto& geom = pInfo->pGeometries[i];
2603
2604 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2605 if (vertex_buffer) {
2606 cb_state->AddChild(vertex_buffer);
2607 }
2608 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2609 if (index_buffer) {
2610 cb_state->AddChild(index_buffer);
2611 }
2612 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2613 if (transform_buffer) {
2614 cb_state->AddChild(transform_buffer);
2615 }
2616
2617 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2618 if (aabb_buffer) {
2619 cb_state->AddChild(aabb_buffer);
2620 }
2621 }
2622
locke-lunargd556cc32019-09-17 01:21:23 -06002623 }
2624 cb_state->hasBuildAccelerationStructureCmd = true;
2625}
2626
2627void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2628 VkAccelerationStructureNV dst,
2629 VkAccelerationStructureNV src,
2630 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002631 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002632 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002633 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2634 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002635 if (!disabled[command_buffer_state]) {
2636 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2637 }
locke-lunargd556cc32019-09-17 01:21:23 -06002638 if (dst_as_state != nullptr && src_as_state != nullptr) {
2639 dst_as_state->built = true;
2640 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002641 }
2642 }
2643}
2644
Jeff Bolz95176d02020-04-01 00:36:16 -05002645void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2646 VkAccelerationStructureKHR accelerationStructure,
2647 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002648 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002649}
2650
Jeff Bolz95176d02020-04-01 00:36:16 -05002651void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2652 VkAccelerationStructureNV accelerationStructure,
2653 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002654 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002655}
2656
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002657void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2658 uint32_t viewportCount,
2659 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002660 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002661 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002662}
2663
locke-lunargd556cc32019-09-17 01:21:23 -06002664void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002665 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002666 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002667}
2668
2669void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2670 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002671 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002672 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002673}
2674
2675void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2676 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002677 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002678 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002679}
2680
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002681void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2682 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002683 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002684 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002685 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2686 cb_state->scissorMask |= bits;
2687 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002688}
2689
locke-lunargd556cc32019-09-17 01:21:23 -06002690void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002691 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002692 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002693}
2694
2695void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2696 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002697 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002698 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002699}
2700
2701void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2702 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002703 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002704 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002705}
2706
2707void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2708 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002709 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002710 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002711}
2712
2713void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2714 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002715 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002716 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002717}
2718
locke-lunargd556cc32019-09-17 01:21:23 -06002719// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2720void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2721 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2722 uint32_t firstSet, uint32_t setCount,
2723 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2724 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002725 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002726 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002727 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002728 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002729
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002730 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2731 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002732}
2733
locke-lunargd556cc32019-09-17 01:21:23 -06002734void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2735 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2736 uint32_t set, uint32_t descriptorWriteCount,
2737 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002738 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002739 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002740 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002741}
2742
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002743void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2744 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2745 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002746 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2747 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002748 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002749 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2750 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002751
2752 auto &push_constant_data = cb_state->push_constant_data;
2753 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2754 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002755 cb_state->push_constant_pipeline_layout_set = layout;
2756
2757 auto flags = stageFlags;
2758 uint32_t bit_shift = 0;
2759 while (flags) {
2760 if (flags & 1) {
2761 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2762 const auto it = cb_state->push_constant_data_update.find(flag);
2763
2764 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002765 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002766 }
2767 }
2768 flags = flags >> 1;
2769 ++bit_shift;
2770 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002771 }
2772}
2773
locke-lunargd556cc32019-09-17 01:21:23 -06002774void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2775 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002776 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002777
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002778 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002779 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002780 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002781 cb_state->index_buffer_binding.offset = offset;
2782 cb_state->index_buffer_binding.index_type = indexType;
2783 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002784 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002785 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002786 }
locke-lunargd556cc32019-09-17 01:21:23 -06002787}
2788
2789void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2790 uint32_t bindingCount, const VkBuffer *pBuffers,
2791 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002792 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002793 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002794
2795 uint32_t end = firstBinding + bindingCount;
2796 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2797 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2798 }
2799
2800 for (uint32_t i = 0; i < bindingCount; ++i) {
2801 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002802 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002803 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002804 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2805 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002806 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002807 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002808 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002809 }
locke-lunargd556cc32019-09-17 01:21:23 -06002810 }
2811}
2812
2813void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2814 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002815 if (disabled[command_buffer_state]) return;
2816
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002817 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002818 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002819}
2820
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002821void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2822 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002823 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002824 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002825}
2826
2827void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2828 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002829 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002830 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2831
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002832 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2833 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002834}
2835
Tony-LunarGc43525f2021-11-15 16:12:38 -07002836void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2837 const VkDependencyInfo* pDependencyInfo) {
2838 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2839 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2840
2841 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2842 cb_state->RecordBarriers(*pDependencyInfo);
2843}
2844
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002845void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2846 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002847 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002848 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002849}
2850
2851void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2852 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002853 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002854 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002855}
2856
Tony-LunarGa2662db2021-11-16 07:26:24 -07002857void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2858 VkPipelineStageFlags2 stageMask) {
2859 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2860 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2861}
2862
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002863void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2864 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2865 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2866 uint32_t bufferMemoryBarrierCount,
2867 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2868 uint32_t imageMemoryBarrierCount,
2869 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002870 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2871 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002872 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2873 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002874}
2875
2876void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2877 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002878 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002879 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002880 const auto &dep_info = pDependencyInfos[i];
2881 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2882 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2883 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002884 }
2885}
2886
Tony-LunarG1364cf52021-11-17 16:10:11 -07002887void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2888 const VkDependencyInfo *pDependencyInfos) {
2889 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2890 for (uint32_t i = 0; i < eventCount; i++) {
2891 const auto &dep_info = pDependencyInfos[i];
2892 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2893 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2894 cb_state->RecordBarriers(dep_info);
2895 }
2896}
2897
Jeremy Gebben79649152021-06-22 14:46:24 -06002898void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2899 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2900 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2901 uint32_t bufferMemoryBarrierCount,
2902 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2903 uint32_t imageMemoryBarrierCount,
2904 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002905 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002906 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2907 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2908 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002909}
2910
2911void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2912 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002913 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002914 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2915 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002916}
2917
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002918void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2919 const VkDependencyInfo *pDependencyInfo) {
2920 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2921 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2922 cb_state->RecordBarriers(*pDependencyInfo);
2923}
2924
locke-lunargd556cc32019-09-17 01:21:23 -06002925void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2926 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002927 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002928
locke-lunargd556cc32019-09-17 01:21:23 -06002929 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002930 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002931 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002932 if (!disabled[query_validation]) {
2933 cb_state->BeginQuery(query);
2934 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002935 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002936 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002937 cb_state->AddChild(pool_state);
2938 }
locke-lunargd556cc32019-09-17 01:21:23 -06002939}
2940
2941void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002942 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002943 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002944 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002945 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002946 if (!disabled[query_validation]) {
2947 cb_state->EndQuery(query_obj);
2948 }
2949 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002950 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002951 cb_state->AddChild(pool_state);
2952 }
locke-lunargd556cc32019-09-17 01:21:23 -06002953}
2954
2955void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2956 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002957 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002958 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002959
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002960 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002961 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002962
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002963 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002964 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002965 cb_state->AddChild(pool_state);
2966 }
locke-lunargd556cc32019-09-17 01:21:23 -06002967}
2968
2969void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2970 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2971 VkDeviceSize dstOffset, VkDeviceSize stride,
2972 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002973 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2974
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002975 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002976 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002977 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002978 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002979 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002980 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002981}
2982
2983void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2984 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002985 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002986 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002987}
2988
2989void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2990 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2991 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002992 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002993 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002994}
2995
Tony-LunarGde9936b2021-11-17 15:34:11 -07002996void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
2997 VkQueryPool queryPool, uint32_t slot) {
2998 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2999 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3000}
3001
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003002void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3003 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3004 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3005 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003006 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003007 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003008 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003009 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003010 cb_state->AddChild(pool_state);
3011 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003012 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003013}
3014
locke-lunargd556cc32019-09-17 01:21:23 -06003015void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3016 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3017 VkResult result) {
3018 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003019
Jeremy Gebben88f58142021-06-01 10:07:52 -06003020 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003021 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003022 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003023
locke-lunargd556cc32019-09-17 01:21:23 -06003024 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003025 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003026 }
3027 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003028
Jeremy Gebben9f537102021-10-05 16:37:12 -06003029 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003030 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003031}
3032
locke-lunargd556cc32019-09-17 01:21:23 -06003033void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3034 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3035 VkResult result) {
3036 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003037 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003038}
3039
Mike Schuchardt2df08912020-12-15 16:28:09 -08003040void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003041 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3042 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003043 if (VK_SUCCESS != result) return;
3044
Jeremy Gebben082a9832021-10-28 13:40:11 -06003045 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003046}
3047
Mike Schuchardt2df08912020-12-15 16:28:09 -08003048void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003049 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3050 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003051 if (VK_SUCCESS != result) return;
3052
Jeremy Gebben082a9832021-10-28 13:40:11 -06003053 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003054}
3055
locke-lunargd556cc32019-09-17 01:21:23 -06003056void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3057 const VkRenderPassBeginInfo *pRenderPassBegin,
3058 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003059 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003060 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003061}
3062
3063void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3064 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003065 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003066 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003067 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003068}
3069
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003070void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3071 uint32_t counterBufferCount,
3072 const VkBuffer *pCounterBuffers,
3073 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003074 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003075
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003076 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003077 cb_state->transform_feedback_active = true;
3078}
3079
3080void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3081 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3082 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003083 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003084
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003085 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003086 cb_state->transform_feedback_active = false;
3087}
3088
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003089void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3090 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003091 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003092
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003093 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003094 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003095 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3096 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003097}
3098
3099void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003100 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003101
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003102 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003103 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003104 cb_state->conditional_rendering_inside_render_pass = false;
3105 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003106}
3107
amhagana448ea52021-11-02 14:09:14 -04003108void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003109 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003110 cb_state->activeRenderPass = nullptr;
3111}
3112
3113void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3114 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003115 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003116 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3117}
3118
Tony-LunarG40b33882021-12-02 12:40:11 -07003119void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3120 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3121 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3122}
3123
amhagana448ea52021-11-02 14:09:14 -04003124void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3125 RecordCmdEndRenderingRenderPassState(commandBuffer);
3126}
3127
Tony-LunarG40b33882021-12-02 12:40:11 -07003128void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3129 RecordCmdEndRenderingRenderPassState(commandBuffer);
3130}
3131
Tony-LunarG977448c2019-12-02 14:52:02 -07003132void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3133 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003134 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003135 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003136 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003137}
3138
locke-lunargd556cc32019-09-17 01:21:23 -06003139void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003140 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003141 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003142}
3143
3144void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003145 const VkSubpassBeginInfo *pSubpassBeginInfo,
3146 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003147 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003148 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003149}
3150
Tony-LunarG977448c2019-12-02 14:52:02 -07003151void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003152 const VkSubpassBeginInfo *pSubpassBeginInfo,
3153 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003154 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003155 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003156}
3157
3158void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003159 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003160 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003161}
3162
3163void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003164 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003165 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003166 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003167}
3168
Tony-LunarG977448c2019-12-02 14:52:02 -07003169void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003170 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003171 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003172 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003173}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003174
locke-lunargd556cc32019-09-17 01:21:23 -06003175void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3176 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003177 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003178
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003179 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003180}
3181
3182void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3183 VkFlags flags, void **ppData, VkResult result) {
3184 if (VK_SUCCESS != result) return;
3185 RecordMappedMemory(mem, offset, size, ppData);
3186}
3187
3188void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003189 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003190 if (mem_info) {
3191 mem_info->mapped_range = MemRange();
3192 mem_info->p_driver_data = nullptr;
3193 }
3194}
3195
3196void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003197 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003198 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003199 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3200 // See: VUID-vkGetImageSubresourceLayout-image-01895
3201 image_state->fragment_encoder =
3202 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003203 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003204 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003205 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003206 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003207 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003208
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003209 if (!swapchain_image.fake_base_address) {
3210 auto size = image_state->fragment_encoder->TotalSize();
3211 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003212 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003213 // All images bound to this swapchain and index are aliases
3214 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003215 }
3216 } else {
3217 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003218 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003219 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003220 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003221 }
locke-lunargd556cc32019-09-17 01:21:23 -06003222 }
locke-lunargd556cc32019-09-17 01:21:23 -06003223 }
3224}
3225
3226void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3227 VkDeviceSize memoryOffset, VkResult result) {
3228 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003229 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003230 bind_info.image = image;
3231 bind_info.memory = mem;
3232 bind_info.memoryOffset = memoryOffset;
3233 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003234}
3235
3236void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003237 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003238 if (VK_SUCCESS != result) return;
3239 for (uint32_t i = 0; i < bindInfoCount; i++) {
3240 UpdateBindImageMemoryState(pBindInfos[i]);
3241 }
3242}
3243
3244void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003245 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003246 if (VK_SUCCESS != result) return;
3247 for (uint32_t i = 0; i < bindInfoCount; i++) {
3248 UpdateBindImageMemoryState(pBindInfos[i]);
3249 }
3250}
3251
3252void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003253 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003254 if (event_state) {
3255 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3256 }
locke-lunargd556cc32019-09-17 01:21:23 -06003257}
3258
3259void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3260 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3261 VkResult result) {
3262 if (VK_SUCCESS != result) return;
3263 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3264 pImportSemaphoreFdInfo->flags);
3265}
3266
3267void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003268 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003269 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003270 if (semaphore_state) {
3271 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003272 }
3273}
3274
3275#ifdef VK_USE_PLATFORM_WIN32_KHR
3276void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3277 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3278 if (VK_SUCCESS != result) return;
3279 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3280 pImportSemaphoreWin32HandleInfo->flags);
3281}
3282
3283void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3284 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3285 HANDLE *pHandle, VkResult result) {
3286 if (VK_SUCCESS != result) return;
3287 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3288}
3289
3290void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3291 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3292 if (VK_SUCCESS != result) return;
3293 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3294 pImportFenceWin32HandleInfo->flags);
3295}
3296
3297void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3298 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3299 HANDLE *pHandle, VkResult result) {
3300 if (VK_SUCCESS != result) return;
3301 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3302}
3303#endif
3304
3305void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3306 VkResult result) {
3307 if (VK_SUCCESS != result) return;
3308 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3309}
3310
Mike Schuchardt2df08912020-12-15 16:28:09 -08003311void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3312 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003313 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003314
3315 if (fence_node) {
3316 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003317 }
3318}
3319
3320void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3321 VkResult result) {
3322 if (VK_SUCCESS != result) return;
3323 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3324}
3325
Mike Schuchardt2df08912020-12-15 16:28:09 -08003326void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003327 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003328 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003329 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003330 }
3331}
3332
3333void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3334 VkResult result) {
3335 if (VK_SUCCESS != result) return;
3336 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3337}
3338
3339void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3340 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3341 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003342 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003343}
3344
3345void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003346 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003347 SWAPCHAIN_NODE *old_swapchain_state) {
3348 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003349 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003350 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003351 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003352 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3353 surface_state->AddParent(swapchain.get());
3354 surface_state->swapchain = swapchain.get();
3355 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003356 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003357 } else {
3358 surface_state->swapchain = nullptr;
3359 }
3360 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003361 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003362 if (old_swapchain_state) {
3363 old_swapchain_state->retired = true;
3364 }
3365 return;
3366}
3367
3368void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3369 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3370 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003371 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003372 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003373 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003374}
3375
3376void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3377 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003378 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003379}
3380
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003381void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3382 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3383 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3384 VkResult result) {
3385 if (VK_SUCCESS != result) return;
3386 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003387 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003388}
3389
locke-lunargd556cc32019-09-17 01:21:23 -06003390void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003391 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003392 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3393 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003394 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003395 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003396 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003397 }
3398 }
3399
Tony-LunarG6f887e52021-07-27 11:23:14 -06003400 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003401 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3402 // 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
3403 // confused itself just as much.
3404 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3405 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3406 // Mark the image as having been released to the WSI
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003407 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003408 if (swapchain_data) {
3409 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003410 if (present_id_info) {
3411 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3412 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3413 }
3414 }
locke-lunargd556cc32019-09-17 01:21:23 -06003415 }
3416 }
locke-lunargd556cc32019-09-17 01:21:23 -06003417}
3418
3419void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3420 const VkSwapchainCreateInfoKHR *pCreateInfos,
3421 const VkAllocationCallbacks *pAllocator,
3422 VkSwapchainKHR *pSwapchains, VkResult result) {
3423 if (pCreateInfos) {
3424 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003425 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003426 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003427 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3428 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003429 }
3430 }
3431}
3432
3433void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3434 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003435 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003436 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003437 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3438 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003439 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003440 }
3441
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003442 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003443 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003444 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3445 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003446 semaphore_state->EnqueueAcquire();
locke-lunargd556cc32019-09-17 01:21:23 -06003447 }
3448
3449 // Mark the image as acquired.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003450 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003451 if (swapchain_data) {
3452 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003453 }
3454}
3455
3456void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3457 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3458 VkResult result) {
3459 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3460 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3461}
3462
3463void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3464 uint32_t *pImageIndex, VkResult result) {
3465 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3466 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3467 pAcquireInfo->fence, pImageIndex);
3468}
3469
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003470std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3471 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3472}
3473
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003474void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3475 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3476 VkResult result) {
3477 if (result != VK_SUCCESS) {
3478 return;
3479 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003480 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003481 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003482 // this can fail if the allocator fails
3483 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3484 if (result != VK_SUCCESS) {
3485 return;
3486 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003487 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003488 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3489 if (result != VK_SUCCESS) {
3490 return;
3491 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003492
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003493 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003494 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003495 }
3496}
3497
3498// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003499static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003500 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003501}
3502
3503void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3504 uint32_t *pQueueFamilyPropertyCount,
3505 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003506 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3507 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003508 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003509}
3510
3511void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003512 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003513 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3514 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003515 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003516}
3517
3518void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003519 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003520 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3521 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003522 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003523}
3524void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3525 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003526 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003527}
3528
Jeremy Gebben082a9832021-10-28 13:40:11 -06003529void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003530
3531void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3532 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3533 const VkAllocationCallbacks *pAllocator,
3534 VkSurfaceKHR *pSurface, VkResult result) {
3535 if (VK_SUCCESS != result) return;
3536 RecordVulkanSurface(pSurface);
3537}
3538
3539#ifdef VK_USE_PLATFORM_ANDROID_KHR
3540void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3541 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3542 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3543 VkResult result) {
3544 if (VK_SUCCESS != result) return;
3545 RecordVulkanSurface(pSurface);
3546}
3547#endif // VK_USE_PLATFORM_ANDROID_KHR
3548
3549#ifdef VK_USE_PLATFORM_IOS_MVK
3550void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3551 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3552 VkResult result) {
3553 if (VK_SUCCESS != result) return;
3554 RecordVulkanSurface(pSurface);
3555}
3556#endif // VK_USE_PLATFORM_IOS_MVK
3557
3558#ifdef VK_USE_PLATFORM_MACOS_MVK
3559void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3560 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3561 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3562 VkResult result) {
3563 if (VK_SUCCESS != result) return;
3564 RecordVulkanSurface(pSurface);
3565}
3566#endif // VK_USE_PLATFORM_MACOS_MVK
3567
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003568#ifdef VK_USE_PLATFORM_METAL_EXT
3569void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3570 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3571 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3572 VkResult result) {
3573 if (VK_SUCCESS != result) return;
3574 RecordVulkanSurface(pSurface);
3575}
3576#endif // VK_USE_PLATFORM_METAL_EXT
3577
locke-lunargd556cc32019-09-17 01:21:23 -06003578#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3579void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3580 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3581 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3582 VkResult result) {
3583 if (VK_SUCCESS != result) return;
3584 RecordVulkanSurface(pSurface);
3585}
3586#endif // VK_USE_PLATFORM_WAYLAND_KHR
3587
3588#ifdef VK_USE_PLATFORM_WIN32_KHR
3589void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3590 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3591 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3592 VkResult result) {
3593 if (VK_SUCCESS != result) return;
3594 RecordVulkanSurface(pSurface);
3595}
3596#endif // VK_USE_PLATFORM_WIN32_KHR
3597
3598#ifdef VK_USE_PLATFORM_XCB_KHR
3599void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3600 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3601 VkResult result) {
3602 if (VK_SUCCESS != result) return;
3603 RecordVulkanSurface(pSurface);
3604}
3605#endif // VK_USE_PLATFORM_XCB_KHR
3606
3607#ifdef VK_USE_PLATFORM_XLIB_KHR
3608void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3609 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3610 VkResult result) {
3611 if (VK_SUCCESS != result) return;
3612 RecordVulkanSurface(pSurface);
3613}
3614#endif // VK_USE_PLATFORM_XLIB_KHR
3615
Niklas Haas8b84af12020-04-19 22:20:11 +02003616void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3617 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3618 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3619 VkResult result) {
3620 if (VK_SUCCESS != result) return;
3621 RecordVulkanSurface(pSurface);
3622}
3623
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003624void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3625 VkSurfaceKHR surface,
3626 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3627 VkResult result) {
3628 if (VK_SUCCESS != result) return;
3629 auto surface_state = Get<SURFACE_STATE>(surface);
3630 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3631}
3632
3633void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3634 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3635 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3636 if (VK_SUCCESS != result) return;
3637 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3638 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3639}
3640
3641void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3642 VkSurfaceKHR surface,
3643 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3644 VkResult result) {
3645 auto surface_state = Get<SURFACE_STATE>(surface);
3646 VkSurfaceCapabilitiesKHR caps{
3647 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3648 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3649 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3650 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3651 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3652 };
3653 surface_state->SetCapabilities(physicalDevice, caps);
3654}
3655
locke-lunargd556cc32019-09-17 01:21:23 -06003656void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3657 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3658 VkBool32 *pSupported, VkResult result) {
3659 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003660 auto surface_state = Get<SURFACE_STATE>(surface);
3661 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3662}
3663
3664void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3665 VkSurfaceKHR surface,
3666 uint32_t *pPresentModeCount,
3667 VkPresentModeKHR *pPresentModes,
3668 VkResult result) {
3669 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3670
3671 if (pPresentModes) {
3672 auto surface_state = Get<SURFACE_STATE>(surface);
3673 surface_state->SetPresentModes(physicalDevice,
3674 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3675 }
3676}
3677
3678void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3679 uint32_t *pSurfaceFormatCount,
3680 VkSurfaceFormatKHR *pSurfaceFormats,
3681 VkResult result) {
3682 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3683
3684 if (pSurfaceFormats) {
3685 auto surface_state = Get<SURFACE_STATE>(surface);
3686 surface_state->SetFormats(physicalDevice,
3687 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3688 }
3689}
3690
3691void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3692 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3693 uint32_t *pSurfaceFormatCount,
3694 VkSurfaceFormat2KHR *pSurfaceFormats,
3695 VkResult result) {
3696 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3697
3698 if (pSurfaceFormats) {
3699 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3700 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3701 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3702 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3703 }
3704 surface_state->SetFormats(physicalDevice, std::move(fmts));
3705 }
locke-lunargd556cc32019-09-17 01:21:23 -06003706}
3707
locke-lunargd556cc32019-09-17 01:21:23 -06003708void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3709 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003710 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003711 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003712 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3713}
3714
3715void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003716 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003717 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003718 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3719}
3720
3721void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3722 const VkDebugUtilsLabelEXT *pLabelInfo) {
3723 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3724
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003725 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003726 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3727 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003728 cb_state->debug_label = LoggingLabel(pLabelInfo);
3729}
3730
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003731void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3732 uint32_t queueFamilyIndex,
3733 uint32_t *pCounterCount,
3734 VkPerformanceCounterKHR *pCounters) {
3735 if (NULL == pCounters) return;
3736
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003737 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3738 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003739
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003740 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3741 queue_family_counters->counters.resize(*pCounterCount);
3742 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003743
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003744 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003745}
3746
3747void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3748 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3749 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3750 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3751 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3752}
3753
3754void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3755 VkResult result) {
3756 if (result == VK_SUCCESS) performance_lock_acquired = true;
3757}
3758
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003759void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3760 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003761 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003762 cmd_buffer.second->performance_lock_released = true;
3763 }
3764}
3765
locke-lunargd556cc32019-09-17 01:21:23 -06003766void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003767 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003768 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003769 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003770}
3771
3772void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003773 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003774 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003775 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003776}
3777
Mike Schuchardt2df08912020-12-15 16:28:09 -08003778void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3779 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003780 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003781}
3782
Mike Schuchardt2df08912020-12-15 16:28:09 -08003783void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3784 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3785 const VkAllocationCallbacks *pAllocator,
3786 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3787 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003788 if (VK_SUCCESS != result) return;
3789 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3790}
3791
3792void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003793 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3794 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003795 if (VK_SUCCESS != result) return;
3796 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3797}
3798
3799void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003800 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003801 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003802 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3803 assert(template_state);
3804 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003805 // TODO: Record template push descriptor updates
3806 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003807 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003808 }
3809 }
3810}
3811
3812void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3813 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3814 const void *pData) {
3815 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3816}
3817
3818void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003819 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003820 const void *pData) {
3821 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3822}
3823
Mike Schuchardt2df08912020-12-15 16:28:09 -08003824void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3825 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3826 VkPipelineLayout layout, uint32_t set,
3827 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003828 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003829
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003830 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003831 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003832 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003833 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003834 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003835 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003836 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003837 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003838 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003839 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003840 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3841 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003842 }
3843}
3844
3845void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3846 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003847 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003848 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003849 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003850 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003851 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003852 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003853 }
3854}
3855
3856void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3857 uint32_t *pPropertyCount,
3858 VkDisplayPlanePropertiesKHR *pProperties,
3859 VkResult result) {
3860 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3861 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3862}
3863
3864void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3865 uint32_t *pPropertyCount,
3866 VkDisplayPlaneProperties2KHR *pProperties,
3867 VkResult result) {
3868 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3869 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3870}
3871
3872void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3873 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3874 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003875 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003876 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003877 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003878}
3879
3880void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3881 uint32_t query, uint32_t index) {
3882 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003883 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003884 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003885 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003886}
3887
3888void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3889 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003890 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003891
3892 if (create_info->format != VK_FORMAT_UNDEFINED) {
3893 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003894 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003895 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3896 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003897 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003898
Jeremy Gebben082a9832021-10-28 13:40:11 -06003899 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003900}
3901
3902void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3903 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3904 const VkAllocationCallbacks *pAllocator,
3905 VkSamplerYcbcrConversion *pYcbcrConversion,
3906 VkResult result) {
3907 if (VK_SUCCESS != result) return;
3908 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3909}
3910
3911void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3912 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3913 const VkAllocationCallbacks *pAllocator,
3914 VkSamplerYcbcrConversion *pYcbcrConversion,
3915 VkResult result) {
3916 if (VK_SUCCESS != result) return;
3917 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3918}
3919
3920void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3921 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003922 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003923}
3924
3925void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3926 VkSamplerYcbcrConversion ycbcrConversion,
3927 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003928 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003929}
3930
Tony-LunarG977448c2019-12-02 14:52:02 -07003931void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3932 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003933 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003934 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003935
3936 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003937 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003938 if (!query_pool_state) return;
3939
3940 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003941 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3942 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003943 auto query_index = firstQuery + i;
3944 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003945 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003946 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003947 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003948 }
3949 }
locke-lunargd556cc32019-09-17 01:21:23 -06003950 }
3951}
3952
Tony-LunarG977448c2019-12-02 14:52:02 -07003953void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3954 uint32_t queryCount) {
3955 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3956}
3957
3958void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3959 uint32_t queryCount) {
3960 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3961}
3962
locke-lunargd556cc32019-09-17 01:21:23 -06003963void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003964 const UPDATE_TEMPLATE_STATE *template_state,
3965 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003966 // Translate the templated update into a normal update for validation...
3967 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3968 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3969 decoded_update.desc_writes.data(), 0, NULL);
3970}
3971
3972// Update the common AllocateDescriptorSetsData
3973void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003974 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003975 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003976 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003977 if (layout) {
3978 ds_data->layout_nodes[i] = layout;
3979 // Count total descriptors required per type
3980 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3981 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003982 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3983 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003984 }
3985 }
3986 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3987 }
3988}
3989
locke-lunargd556cc32019-09-17 01:21:23 -06003990void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3991 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003992 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003993 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003994}
3995
Tony-LunarG745150c2021-07-02 15:07:31 -06003996void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3997 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3998 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003999 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004000 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004001}
4002
locke-lunargd556cc32019-09-17 01:21:23 -06004003void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4004 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4005 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004006 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004007 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004008}
4009
Tony-LunarG745150c2021-07-02 15:07:31 -06004010void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4011 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4012 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4013 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004014 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004015 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004016}
4017
locke-lunargd556cc32019-09-17 01:21:23 -06004018void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4019 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004020 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004021 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004022 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004023 if (!disabled[command_buffer_state]) {
4024 cb_state->AddChild(buffer_state);
4025 }
locke-lunargd556cc32019-09-17 01:21:23 -06004026}
4027
4028void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4029 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004030 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004031 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004032 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004033 if (!disabled[command_buffer_state]) {
4034 cb_state->AddChild(buffer_state);
4035 }
locke-lunargd556cc32019-09-17 01:21:23 -06004036}
4037
4038void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
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->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004041}
4042
4043void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4044 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004045 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004046 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004047 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004048 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004049 cb_state->AddChild(buffer_state);
4050 }
locke-lunargd556cc32019-09-17 01:21:23 -06004051}
4052
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004053void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4054 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004055 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004056 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4057}
4058
4059void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4060 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004061 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004062 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4063}
4064
Tony-LunarG977448c2019-12-02 14:52:02 -07004065void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4066 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004067 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004068 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004069 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004070 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004071 auto buffer_state = Get<BUFFER_STATE>(buffer);
4072 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004073 cb_state->AddChild(buffer_state);
4074 cb_state->AddChild(count_buffer_state);
4075 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004076}
4077
locke-lunargd556cc32019-09-17 01:21:23 -06004078void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4079 VkDeviceSize offset, VkBuffer countBuffer,
4080 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4081 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004082 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004083 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004084}
4085
4086void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4087 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4088 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004089 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004090 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004091}
4092
4093void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4094 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004095 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004096 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004097 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004098 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004099 auto buffer_state = Get<BUFFER_STATE>(buffer);
4100 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004101 cb_state->AddChild(buffer_state);
4102 cb_state->AddChild(count_buffer_state);
4103 }
locke-lunargd556cc32019-09-17 01:21:23 -06004104}
4105
4106void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4107 VkDeviceSize offset, VkBuffer countBuffer,
4108 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4109 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004110 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004111 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004112}
4113
4114void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4115 VkDeviceSize offset, VkBuffer countBuffer,
4116 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4117 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004118 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004119 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004120}
4121
4122void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4123 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004124 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004125 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004126}
4127
4128void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4129 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004130 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004131 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004132 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004133 if (!disabled[command_buffer_state] && buffer_state) {
4134 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004135 }
4136}
4137
4138void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4139 VkDeviceSize offset, VkBuffer countBuffer,
4140 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4141 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004142 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004143 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004144 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004145 auto buffer_state = Get<BUFFER_STATE>(buffer);
4146 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004147 if (buffer_state) {
4148 cb_state->AddChild(buffer_state);
4149 }
4150 if (count_buffer_state) {
4151 cb_state->AddChild(count_buffer_state);
4152 }
locke-lunargd556cc32019-09-17 01:21:23 -06004153 }
4154}
4155
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004156void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4157 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4158 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4159 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4160 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4161 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4162 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004163 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004164 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004165 cb_state->hasTraceRaysCmd = true;
4166}
4167
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004168void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4169 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4170 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4171 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4172 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4173 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004174 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004175 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004176 cb_state->hasTraceRaysCmd = true;
4177}
4178
4179void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4180 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4181 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4182 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4183 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4184 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004185 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004186 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004187 cb_state->hasTraceRaysCmd = true;
4188}
4189
locke-lunargd556cc32019-09-17 01:21:23 -06004190void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4191 const VkAllocationCallbacks *pAllocator,
4192 VkShaderModule *pShaderModule, VkResult result,
4193 void *csm_state_data) {
4194 if (VK_SUCCESS != result) return;
4195 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4196
sfricke-samsung45996a42021-09-16 13:45:27 -07004197 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004198 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004199 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4200 csm_state->unique_shader_id)
4201 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004202 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004203}
4204
John Zulauf22b0fbe2019-10-15 06:26:16 -06004205void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4206 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4207 VkResult result) {
4208 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004209 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004210
4211 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4212
4213 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004214 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004215 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004216 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004217
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004218 auto format_features = GetImageFormatFeatures(
4219 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4220 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004221
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06004222 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004223 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004224 if (!swapchain_image.fake_base_address) {
4225 auto size = image_state->fragment_encoder->TotalSize();
4226 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004227 }
4228
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004229 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004230 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004231 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004232 }
4233 }
4234
4235 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004236 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4237 }
4238}
sourav parmar35e7a002020-06-09 17:58:44 -07004239
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004240void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4241 const VkCopyAccelerationStructureInfoKHR *pInfo,
4242 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004243 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4244 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004245 if (dst_as_state != nullptr && src_as_state != nullptr) {
4246 dst_as_state->built = true;
4247 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4248 }
4249}
4250
sourav parmar35e7a002020-06-09 17:58:44 -07004251void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4252 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004253 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004254 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004255 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004256 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4257 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004258 if (dst_as_state != nullptr && src_as_state != nullptr) {
4259 dst_as_state->built = true;
4260 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004261 if (!disabled[command_buffer_state]) {
4262 cb_state->AddChild(dst_as_state);
4263 cb_state->AddChild(src_as_state);
4264 }
sourav parmar35e7a002020-06-09 17:58:44 -07004265 }
4266 }
4267}
Piers Daniell39842ee2020-07-10 16:42:33 -06004268
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004269void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4270 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4271 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4272 if (cb_state) {
4273 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4274 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4275 if (!disabled[command_buffer_state]) {
4276 cb_state->AddChild(src_as_state);
4277 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004278 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4279 if (dst_buffer) {
4280 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004281 }
4282 }
4283}
4284
4285void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4286 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4287 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4288 if (cb_state) {
4289 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4290 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004291 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4292 if (buffer_state) {
4293 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004294 }
4295 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4296 cb_state->AddChild(dst_as_state);
4297 }
4298 }
4299}
4300
Piers Daniell39842ee2020-07-10 16:42:33 -06004301void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004302 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004303 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004304}
4305
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004306void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4307 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4308 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4309}
4310
Piers Daniell39842ee2020-07-10 16:42:33 -06004311void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004312 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004313 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004314}
4315
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004316void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4317 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4318 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4319}
4320
Piers Daniell39842ee2020-07-10 16:42:33 -06004321void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4322 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004323 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004324 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004325 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004326}
4327
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004328void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4329 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004330 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004331 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4332 cb_state->primitiveTopology = primitiveTopology;
4333}
4334
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004335void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4336 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004337 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4338 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004339 uint32_t bits = (1u << viewportCount) - 1u;
4340 cb_state->viewportWithCountMask |= bits;
4341 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004342 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004343 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004344
4345 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4346 for (size_t i = 0; i < viewportCount; ++i) {
4347 cb_state->dynamicViewports[i] = pViewports[i];
4348 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004349}
4350
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004351void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4352 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004353 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004354}
4355
4356void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004357 const VkViewport *pViewports) {
4358 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004359}
4360
4361void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4362 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004363 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004364 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004365 uint32_t bits = (1u << scissorCount) - 1u;
4366 cb_state->scissorWithCountMask |= bits;
4367 cb_state->trashedScissorMask &= ~bits;
4368 cb_state->scissorWithCountCount = scissorCount;
4369 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004370}
4371
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004372void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4373 const VkRect2D *pScissors) {
4374 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4375}
4376
4377void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4378 const VkRect2D *pScissors) {
4379 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4380}
4381
4382void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4383 uint32_t bindingCount, const VkBuffer *pBuffers,
4384 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4385 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004386 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004387 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004388
4389 uint32_t end = firstBinding + bindingCount;
4390 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4391 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4392 }
4393
4394 for (uint32_t i = 0; i < bindingCount; ++i) {
4395 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004396 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004397 vertex_buffer_binding.offset = pOffsets[i];
4398 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4399 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4400 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004401 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004402 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004403 }
4404 }
4405}
4406
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004407void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4408 uint32_t bindingCount, const VkBuffer *pBuffers,
4409 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4410 const VkDeviceSize *pStrides) {
4411 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4412 CMD_BINDVERTEXBUFFERS2EXT);
4413}
4414
4415void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4416 uint32_t bindingCount, const VkBuffer *pBuffers,
4417 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4418 const VkDeviceSize *pStrides) {
4419 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4420 CMD_BINDVERTEXBUFFERS2);
4421}
4422
Piers Daniell39842ee2020-07-10 16:42:33 -06004423void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004424 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004425 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004426}
4427
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004428void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4429 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4430 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4431}
4432
Piers Daniell39842ee2020-07-10 16:42:33 -06004433void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004434 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004435 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004436}
4437
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004438void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4439 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4440 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4441}
4442
Piers Daniell39842ee2020-07-10 16:42:33 -06004443void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004444 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004445 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004446}
4447
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004448void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4449 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4450 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4451}
4452
Piers Daniell39842ee2020-07-10 16:42:33 -06004453void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4454 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004455 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004456 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004457}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004458
4459void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4460 VkBool32 depthBoundsTestEnable) {
4461 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4462 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4463}
4464
Piers Daniell39842ee2020-07-10 16:42:33 -06004465void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004466 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004467 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004468}
4469
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004470void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4471 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4472 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4473}
4474
Piers Daniell39842ee2020-07-10 16:42:33 -06004475void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4476 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4477 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004478 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004479 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004480}
locke-lunarg4189aa22020-10-21 00:23:48 -06004481
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004482void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4483 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4484 VkCompareOp compareOp) {
4485 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4486 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4487}
4488
locke-lunarg4189aa22020-10-21 00:23:48 -06004489void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4490 uint32_t discardRectangleCount,
4491 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004492 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004493 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004494}
4495
4496void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4497 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004498 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004499 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004500}
4501
4502void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4503 VkCoarseSampleOrderTypeNV sampleOrderType,
4504 uint32_t customSampleOrderCount,
4505 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004506 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004507 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004508}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004509
4510void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004511 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004512 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004513}
4514
4515void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004516 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004517 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004518}
4519
4520void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4521 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004522 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004523 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004524}
4525
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004526void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4527 VkBool32 rasterizerDiscardEnable) {
4528 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4529 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4530}
4531
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004532void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004533 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004534 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004535}
4536
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004537void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4538 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4539 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4540}
4541
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004542void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4543 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004544 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004545 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004546}
Piers Daniell924cd832021-05-18 13:48:47 -06004547
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004548void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4549 VkBool32 primitiveRestartEnable) {
4550 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4551 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4552}
4553
Piers Daniell924cd832021-05-18 13:48:47 -06004554void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4555 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4556 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4557 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004558 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004559 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4560
4561 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4562 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4563 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004564 if (pipeline_state->create_info.graphics.pDynamicState) {
4565 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4566 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004567 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4568 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4569 break;
4570 }
4571 }
4572 }
4573 }
4574 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004575}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004576
4577void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004578 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004579 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004580 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004581 // address is used for GPU-AV and ray tracing buffer validation
4582 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004583 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004584 }
4585}
4586
4587void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4588 VkDeviceAddress address) {
4589 RecordGetBufferDeviceAddress(pInfo, address);
4590}
4591
4592void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4593 VkDeviceAddress address) {
4594 RecordGetBufferDeviceAddress(pInfo, address);
4595}
4596
4597void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4598 VkDeviceAddress address) {
4599 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004600}
4601
4602std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4603 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004604 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004605}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004606
4607std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4608 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004609 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004610 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4611}