blob: 1294c086e31fddb3ec42617ee4e4f1d4eb2ca82f [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Tobias Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Dave Houlton <daveh@lunarg.com>
21 * Shannon McPherson <shannon@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
28#include "vk_enum_string_helper.h"
29#include "vk_format_utils.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33#include "vk_typemap_helper.h"
34
35#include "chassis.h"
36#include "state_tracker.h"
37#include "shader_validation.h"
Jeremy Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = {
138 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
139 nullptr,
140 };
141
142 // Find the image modifier
143 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
144
145 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
146 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
147 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
148
149 // Second query to have all the modifiers filled
150 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
151
152 // Look for the image modifier in the list
153 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
154 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
155 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
156 break;
157 }
158 }
159 } else {
160 format_features =
161 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
162 }
163 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600164 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
165 nullptr};
166 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200167
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
169 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
170 nullptr};
171 format_properties_2.pNext = (void *)&drm_properties_list;
172 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
173 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
174 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
175 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
176 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200177
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600178 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
179 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
180 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
181 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200182 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200183 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600184 } else {
185 VkFormatProperties format_properties;
186 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
187 format_features =
188 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200189 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600190 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200191}
192
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700193std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
194 VkFormatFeatureFlags2KHR features) {
195 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, features);
196}
197
198std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
199 VkSwapchainKHR swapchain, uint32_t swapchain_index,
200 VkFormatFeatureFlags2KHR features) {
201 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, swapchain, swapchain_index, features);
202}
203
locke-lunargd556cc32019-09-17 01:21:23 -0600204void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
205 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
206 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200207 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700208 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600209 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600210 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600211 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200212 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
213 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
214 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600215 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700216 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600217}
218
219void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600220 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600221}
222
223void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
224 VkImageLayout imageLayout, const VkClearColorValue *pColor,
225 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600226 if (disabled[command_buffer_state]) return;
227
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700228 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600229 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600230 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600231 }
232}
233
234void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
235 VkImageLayout imageLayout,
236 const VkClearDepthStencilValue *pDepthStencil,
237 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600238 if (disabled[command_buffer_state]) return;
239
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700240 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600241 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600242 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600243 }
244}
245
246void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
247 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
248 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600252 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600253}
254
Jeff Leger178b1e52020-10-05 12:22:23 -0400255void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
256 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600257 if (disabled[command_buffer_state]) return;
258
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700259 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600260 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
261 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400262}
263
Tony-LunarGb61514a2021-11-02 12:36:51 -0600264void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
265 if (disabled[command_buffer_state]) return;
266
267 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
268 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
269 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
270}
271
locke-lunargd556cc32019-09-17 01:21:23 -0600272void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
273 VkImageLayout srcImageLayout, VkImage dstImage,
274 VkImageLayout dstImageLayout, uint32_t regionCount,
275 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600276 if (disabled[command_buffer_state]) return;
277
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700278 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600279 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600280}
281
Jeff Leger178b1e52020-10-05 12:22:23 -0400282void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
283 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600284 if (disabled[command_buffer_state]) return;
285
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700286 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600287 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
288 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400289}
290
Tony-LunarG562fc102021-11-12 13:58:35 -0700291void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
292 const VkResolveImageInfo2 *pResolveImageInfo) {
293 if (disabled[command_buffer_state]) return;
294
295 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
296 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
297 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
298}
299
locke-lunargd556cc32019-09-17 01:21:23 -0600300void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
301 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
302 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600303 if (disabled[command_buffer_state]) return;
304
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700305 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600306 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600307}
308
Jeff Leger178b1e52020-10-05 12:22:23 -0400309void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
310 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600311 if (disabled[command_buffer_state]) return;
312
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700313 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600314 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
315 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400316}
317
Tony-LunarG542ae912021-11-04 16:06:44 -0600318void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
319 if (disabled[command_buffer_state]) return;
320
321 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
322 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
323 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
324}
325
locke-lunargd556cc32019-09-17 01:21:23 -0600326void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
327 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
328 VkResult result) {
329 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600330
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600331 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600332
James Rumble2f6e7bb2021-07-13 15:21:20 +0100333 if (pCreateInfo) {
334 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700335 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700336 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100337 // address is used for GPU-AV and ray tracing buffer validation
338 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700339 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100340 }
341 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600342 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600343}
344
345void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
346 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
347 VkResult result) {
348 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600349
Jeremy Gebben9f537102021-10-05 16:37:12 -0600350 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600351
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200352 VkFormatFeatureFlags2KHR buffer_features;
353 if (has_format_feature2) {
354 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
355 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
356 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
357 buffer_features = fmt_props_3.bufferFeatures;
358 } else {
359 VkFormatProperties format_properties;
360 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
361 buffer_features = format_properties.bufferFeatures;
362 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600363
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200364 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600365}
366
367void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
368 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
369 VkResult result) {
370 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600371 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700372
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200373 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600374 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700375 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600376 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700377 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200378 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
379 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
380 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700381 }
382
locke-lunarg9939d4b2020-10-26 20:11:08 -0600383 // 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 -0600384 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600385 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700386 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600387 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700388 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600389 image_format_info.type = image_state->createInfo.imageType;
390 image_format_info.format = image_state->createInfo.format;
391 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600392 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
393 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600394 image_format_info.flags = image_state->createInfo.flags;
395
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600396 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600397
398 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
399 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600400
Jeremy Gebben082a9832021-10-28 13:40:11 -0600401 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600402}
403
404void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
405 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600406 if (disabled[command_buffer_state]) return;
407
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700408 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600409 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600410}
411
Jeff Leger178b1e52020-10-05 12:22:23 -0400412void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600413 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600414 if (disabled[command_buffer_state]) return;
415
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700416 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600417 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
418 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400419}
420
Tony-LunarGef035472021-11-02 10:23:33 -0600421void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
422 if (disabled[command_buffer_state]) return;
423
424 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
425 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
426 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
427}
428
locke-lunargd556cc32019-09-17 01:21:23 -0600429void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
430 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600431 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600432}
433
434void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700435 auto buffer_state = Get<BUFFER_STATE>(buffer);
436 if (buffer_state) {
437 WriteLockGuard guard(buffer_address_lock_);
438 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
439 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600440 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600441}
442
443void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
444 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600445 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600446}
447
448void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
449 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600450 if (disabled[command_buffer_state]) return;
451
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700452 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600453 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600454}
455
456void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
457 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
458 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600459 if (disabled[command_buffer_state]) return;
460
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700461 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600462
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600463 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600464}
465
Jeff Leger178b1e52020-10-05 12:22:23 -0400466void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
467 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600468 if (disabled[command_buffer_state]) return;
469
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700470 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600471 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
472 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400473}
474
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700475void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
476 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
477 if (disabled[command_buffer_state]) return;
478
479 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
480 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
481 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
482}
483
locke-lunargd556cc32019-09-17 01:21:23 -0600484void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
485 VkImageLayout dstImageLayout, uint32_t regionCount,
486 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600487 if (disabled[command_buffer_state]) return;
488
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700489 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600490 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600491}
492
Jeff Leger178b1e52020-10-05 12:22:23 -0400493void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
494 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600495 if (disabled[command_buffer_state]) return;
496
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700497 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600498 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
499 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400500}
501
Tony Barbour845d29b2021-11-09 11:43:14 -0700502void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
503 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
504 if (disabled[command_buffer_state]) return;
505
506 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
507 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
508 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
509}
510
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700511// Gets union of all features defined by Potential Format Features
512// 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 +0200513VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
514 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700515
516 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200517 if (has_format_feature2) {
518 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200519 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
520 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200521 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100522
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200523 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100524
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200525 format_features |= fmt_props_3.linearTilingFeatures;
526 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100527
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200528 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
529 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
530 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
531 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
532 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100533
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200534 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
535 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
536 }
537 }
538 } else {
539 VkFormatProperties format_properties;
540 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
541 format_features |= format_properties.linearTilingFeatures;
542 format_features |= format_properties.optimalTilingFeatures;
543
544 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
545 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
546 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
547
548 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
549
550 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
551 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
552 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
553 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
554
555 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
556 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
557 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700558 }
559 }
560 }
561
562 return format_features;
563}
564
locke-lunargd556cc32019-09-17 01:21:23 -0600565void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
566 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
567 VkResult result) {
568 if (VK_SUCCESS != result) return;
569
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600570 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600571 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
572 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600573 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600574
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600575 device_state->instance_state = this;
576 // Save local link to this device's physical device state
577 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
578 // finish setup in the object representing the device
579 device_state->CreateDevice(pCreateInfo);
580}
581
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -0600582std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags) {
583 return std::make_shared<QUEUE_STATE>(q, index, flags);
584}
585
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600586void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600587 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
588 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700589 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600590 if (features2) {
591 enabled_features_found = &(features2->features);
592 }
593 }
594
locke-lunargd556cc32019-09-17 01:21:23 -0600595 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600596 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600597 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600598 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600599 }
600
Tony-LunarG273f32f2021-09-28 08:56:30 -0600601 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
602 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600603 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600604 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600605 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600606 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
607 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600608 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600609 }
610
611 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
612 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600613 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
614 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600615 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
616 }
617
618 const auto *pipeline_creation_cache_control_features =
619 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
620 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600621 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600622 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
623 }
624
625 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
626 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600627 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600628 }
629
630 const auto *demote_to_helper_invocation_features =
631 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
632 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600633 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600634 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
635 }
636
637 const auto *terminate_invocation_features =
638 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
639 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600640 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600641 }
642
643 const auto *subgroup_size_control_features =
644 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
645 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600646 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
647 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600648 }
649
650 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
651 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600652 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600653 }
654
655 const auto *texture_compression_astchdr_features =
656 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
657 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600658 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600659 }
660
661 const auto *initialize_workgroup_memory_features =
662 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
663 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600664 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600665 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
666 }
667
668 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
669 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600670 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600671 }
672
673 const auto *shader_integer_dot_product_features =
674 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
675 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600676 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600677 }
678
679 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
680 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600681 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600682 }
683 }
684
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700685 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700686 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600687 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700688 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700689 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600690 enabled_features.core12.drawIndirectCount = VK_FALSE;
691 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
692 enabled_features.core12.descriptorIndexing = VK_FALSE;
693 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
694 enabled_features.core12.shaderOutputLayer = VK_FALSE;
695 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
696 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700697
698 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700699
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700700 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700701 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600702 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
703 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700704 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600705 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700706 }
707
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700708 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700709 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600710 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
711 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700712 }
713
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700714 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700715 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600716 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700717 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600718 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700719 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600720 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700721 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700723 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700725 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600726 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700727 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600728 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700729 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600730 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700731 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600732 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700733 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700735 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600738 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700739 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600740 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700741 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700743 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700745 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600746 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700747 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600748 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700749 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600750 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
751 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700752 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600753 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700754 }
755
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700756 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700757 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600758 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 }
760
761 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700762 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700763 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600764 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 }
766
767 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700768 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700769 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600770 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700771 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700772 }
773
774 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700775 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700776 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600777 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 }
779
780 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700781 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700782 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600783 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700784 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700785 }
786
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700787 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700788 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600789 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700790 }
791
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700792 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700793 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600794 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700795 }
796
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700797 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700798 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600799 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
800 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
801 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700802 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800803
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700804 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800805 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600806 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
807 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800808 }
809
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700810 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800811 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600812 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
813 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
814 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800815 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) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600821 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700822 } 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) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600827 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
828 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700829 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600830 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
831 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700832 }
833
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700834 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700835 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600836 enabled_features.core11.multiview = multiview_features->multiview;
837 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
838 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700839 }
840
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700841 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700842 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600843 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
844 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700845 }
846
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700847 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700848 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600849 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700850 }
851
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700852 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700853 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600854 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 }
856
857 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700858 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700859 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600860 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700861 }
862 }
863
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700864 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600865 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600866 physical_device_count = device_group_ci->physicalDeviceCount;
867 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600868 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600869 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600870 }
locke-lunargd556cc32019-09-17 01:21:23 -0600871
sfricke-samsung828e59d2021-08-22 23:20:49 -0700872 // Features from other extensions passesd in create info
873 {
874 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
875 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600876 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700877 }
locke-lunargd556cc32019-09-17 01:21:23 -0600878
sfricke-samsung828e59d2021-08-22 23:20:49 -0700879 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
880 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600881 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700882 }
locke-lunargd556cc32019-09-17 01:21:23 -0600883
sfricke-samsung828e59d2021-08-22 23:20:49 -0700884 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
885 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600886 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700887 }
locke-lunargd556cc32019-09-17 01:21:23 -0600888
sfricke-samsung828e59d2021-08-22 23:20:49 -0700889 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
890 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600891 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700892 }
locke-lunargd556cc32019-09-17 01:21:23 -0600893
sfricke-samsung828e59d2021-08-22 23:20:49 -0700894 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
895 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600896 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700897 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700898
sfricke-samsung828e59d2021-08-22 23:20:49 -0700899 const auto *buffer_device_address_ext_features =
900 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
901 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600902 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700903 }
locke-lunargd556cc32019-09-17 01:21:23 -0600904
sfricke-samsung828e59d2021-08-22 23:20:49 -0700905 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
906 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600907 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700908 }
locke-lunargd556cc32019-09-17 01:21:23 -0600909
sfricke-samsung828e59d2021-08-22 23:20:49 -0700910 const auto *compute_shader_derivatives_features =
911 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
912 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600913 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700914 }
locke-lunargd556cc32019-09-17 01:21:23 -0600915
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 const auto *fragment_shader_barycentric_features =
917 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
918 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600919 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700920 }
locke-lunargd556cc32019-09-17 01:21:23 -0600921
sfricke-samsung828e59d2021-08-22 23:20:49 -0700922 const auto *shader_image_footprint_features =
923 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
924 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600925 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700926 }
locke-lunargd556cc32019-09-17 01:21:23 -0600927
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 const auto *fragment_shader_interlock_features =
929 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
930 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600931 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700932 }
locke-lunargd556cc32019-09-17 01:21:23 -0600933
sfricke-samsung828e59d2021-08-22 23:20:49 -0700934 const auto *texel_buffer_alignment_features =
935 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
936 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600937 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700938 }
locke-lunargd556cc32019-09-17 01:21:23 -0600939
sfricke-samsung828e59d2021-08-22 23:20:49 -0700940 const auto *pipeline_exe_props_features =
941 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
942 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600943 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700944 }
locke-lunargd556cc32019-09-17 01:21:23 -0600945
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 const auto *dedicated_allocation_image_aliasing_features =
947 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
948 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600949 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700950 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500951
sfricke-samsung828e59d2021-08-22 23:20:49 -0700952 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
953 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600954 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700955 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100956
sfricke-samsung828e59d2021-08-22 23:20:49 -0700957 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
958 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600959 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700960 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000961
sfricke-samsung828e59d2021-08-22 23:20:49 -0700962 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
963 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600964 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700965 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800966
sfricke-samsung828e59d2021-08-22 23:20:49 -0700967 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
968 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600969 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700970 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700971
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 const auto *ray_tracing_pipeline_features =
973 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
974 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600975 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700976 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700977
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 const auto *ray_tracing_acceleration_structure_features =
979 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
980 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600981 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700982 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500983
sfricke-samsung828e59d2021-08-22 23:20:49 -0700984 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
985 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600986 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700987 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500988
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 const auto *fragment_density_map_features =
990 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
991 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600992 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700993 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200994
sfricke-samsung828e59d2021-08-22 23:20:49 -0700995 const auto *fragment_density_map_features2 =
996 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
997 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600998 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001000
Agarwal, Arpit78509112022-02-17 15:29:05 -07001001 const auto *fragment_density_map_offset_features =
1002 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1003 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001004 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001005 }
1006
sfricke-samsung828e59d2021-08-22 23:20:49 -07001007 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1008 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001009 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001010 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001011
sfricke-samsung828e59d2021-08-22 23:20:49 -07001012 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1013 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001014 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001015 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001016
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 const auto *fragment_shading_rate_features =
1018 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1019 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001020 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001022
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001023 const auto *fragment_shading_rate_enums_features =
1024 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1025 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001026 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001027 }
1028
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 const auto *extended_dynamic_state_features =
1030 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1031 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001032 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001034
sfricke-samsung828e59d2021-08-22 23:20:49 -07001035 const auto *extended_dynamic_state2_features =
1036 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1037 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001038 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001039 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001040
sfricke-samsung828e59d2021-08-22 23:20:49 -07001041 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1042 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001043 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001044 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001045
sfricke-samsung828e59d2021-08-22 23:20:49 -07001046 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1047 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001048 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001050
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 const auto *shader_integer_functions2_features =
1052 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1053 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001054 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001055 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001056
sfricke-samsung828e59d2021-08-22 23:20:49 -07001057 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1058 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001059 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001060 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001061
sfricke-samsung828e59d2021-08-22 23:20:49 -07001062 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1063 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001064 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001065 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001066
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 const auto *shader_image_atomic_int64_features =
1068 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1069 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001070 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001071 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001072
sfricke-samsung828e59d2021-08-22 23:20:49 -07001073 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1074 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001075 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001076 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001077
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 const auto *conditional_rendering_features =
1079 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1080 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001081 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001082 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001083
sfricke-samsung828e59d2021-08-22 23:20:49 -07001084 const auto *workgroup_memory_explicit_layout_features =
1085 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1086 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001087 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001088 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001089
sfricke-samsung828e59d2021-08-22 23:20:49 -07001090 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1091 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001092 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001093 }
Locke Linf3873542021-04-26 11:25:10 -06001094
sfricke-samsung828e59d2021-08-22 23:20:49 -07001095 const auto *vertex_input_dynamic_state_features =
1096 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1097 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001098 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001100
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 const auto *inherited_viewport_scissor_features =
1102 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1103 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001104 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001106
sfricke-samsung828e59d2021-08-22 23:20:49 -07001107 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1108 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001109 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001111
sfricke-samsung828e59d2021-08-22 23:20:49 -07001112 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1113 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001114 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001115 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001116
sfricke-samsung828e59d2021-08-22 23:20:49 -07001117 const auto *shader_atomic_float2_features =
1118 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1119 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001120 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001121 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001122
sfricke-samsung828e59d2021-08-22 23:20:49 -07001123 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1124 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001125 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001126 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001127
sfricke-samsung828e59d2021-08-22 23:20:49 -07001128 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1129 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001130 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001131 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001132
1133 const auto *ray_tracing_motion_blur_features =
1134 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1135 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001136 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001137 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001138
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001139 const auto *primitive_topology_list_restart_features =
1140 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1141 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001142 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001143 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001144
ziga-lunarge1988962021-09-16 13:32:34 +02001145 const auto *zero_initialize_work_group_memory_features =
1146 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1147 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001148 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001149 }
1150
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001151 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1152 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001153 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001154 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001155
Tony-LunarG69604c42021-11-22 16:00:12 -07001156 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1157 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001158 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001159 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001160
1161 const auto *primitives_generated_query_features =
1162 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1163 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001164 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001165 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001166
1167 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1168 if (image_2d_view_of_3d_features) {
1169 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1170 }
Nathaniel Cesario553ab032022-04-14 10:56:22 -06001171
1172 const auto graphics_pipeline_library_features =
1173 LvlFindInChain<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(pCreateInfo->pNext);
1174 if (graphics_pipeline_library_features) {
1175 enabled_features.graphics_pipeline_library_features = *graphics_pipeline_library_features;
1176 }
ziga-lunarge25f5f02022-04-16 15:07:35 +02001177
1178 const auto shader_subgroup_uniform_control_flow_features =
1179 LvlFindInChain<VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR>(pCreateInfo->pNext);
1180 if (shader_subgroup_uniform_control_flow_features) {
1181 enabled_features.shader_subgroup_uniform_control_flow_features = *shader_subgroup_uniform_control_flow_features;
1182 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001183 }
1184
locke-lunargd556cc32019-09-17 01:21:23 -06001185 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001186 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1187 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001188
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001189 {
1190 uint32_t n_props = 0;
1191 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001192 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001193 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001194 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001195
1196 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001197 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001198 }
1199
1200 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1201 // a path to grab that information from the physical device. This
1202 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1203 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001204 has_format_feature2 =
1205 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1206 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001207 }
1208
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001209 const auto &dev_ext = device_extensions;
1210 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001211
Tony-LunarG273f32f2021-09-28 08:56:30 -06001212 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1213 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001214 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1215 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001216 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001217 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001218 } else {
1219 // VkPhysicalDeviceVulkan11Properties
1220 //
1221 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1222
1223 if (dev_ext.vk_khr_multiview) {
1224 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001225 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1226 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1227 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001228 }
1229
1230 if (dev_ext.vk_khr_maintenance3) {
1231 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001232 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1233 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1234 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001235 }
1236
1237 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001238 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001239 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1240 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1241 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001242 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001243
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001244 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1245 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1246 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1247 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001248
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001249 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001250 }
1251
1252 // VkPhysicalDeviceVulkan12Properties
1253 //
1254 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1255
1256 if (dev_ext.vk_ext_descriptor_indexing) {
1257 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001258 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1259 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001260 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001261 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001262 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001263 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001264 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001265 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001266 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001267 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001268 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001269 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001270 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001271 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1272 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1273 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001274 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001275 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001276 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001277 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001278 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001279 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001280 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001281 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001282 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001283 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001284 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001285 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001286 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001287 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001288 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001289 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001290 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001291 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001292 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001293 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001294 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001295 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001296 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001297 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001298 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001299 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001300 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001301 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001302 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1303 }
1304
1305 if (dev_ext.vk_khr_depth_stencil_resolve) {
1306 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001307 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1308 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1309 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1310 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1311 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001312 }
1313
1314 if (dev_ext.vk_khr_timeline_semaphore) {
1315 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001316 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1317 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001318 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1319 }
1320
1321 if (dev_ext.vk_ext_sampler_filter_minmax) {
1322 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001323 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1324 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001325 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001326 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001327 }
1328
1329 if (dev_ext.vk_khr_shader_float_controls) {
1330 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001331 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1332 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1333 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1334 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001335 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001336 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001337 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001338 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001339 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001340 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1341 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1342 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1343 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1344 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1345 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1346 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1347 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1348 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1349 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1350 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1351 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001352 }
locke-lunargd556cc32019-09-17 01:21:23 -06001353 }
1354
sfricke-samsung828e59d2021-08-22 23:20:49 -07001355 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001356 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1357 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1358 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1359 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1360 &phys_dev_props->inline_uniform_block_props);
1361 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1362 &phys_dev_props->vtx_attrib_divisor_props);
1363 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1364 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1365 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1366 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1367 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1368 &phys_dev_props->texel_buffer_alignment_props);
1369 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1370 &phys_dev_props->fragment_density_map_props);
1371 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1372 &phys_dev_props->fragment_density_map2_props);
1373 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001374 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001375 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1376 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1377 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1378 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1379 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1380 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1381 &phys_dev_props->fragment_shading_rate_props);
1382 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1383 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1384 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1385 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1386 &phys_dev_props->blend_operation_advanced_props);
1387 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1388 &phys_dev_props->conservative_rasterization_props);
1389 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1390 &phys_dev_props->subgroup_size_control_props);
ziga-lunarge25f5f02022-04-16 15:07:35 +02001391 if (api_version >= VK_API_VERSION_1_1) {
1392 GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_properties);
1393 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001394
sfricke-samsung45996a42021-09-16 13:45:27 -07001395 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001396 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001397 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1398 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001399 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1400 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001401
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001402 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001403 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1404 NULL);
1405 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001406
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001407 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1408 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001409 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001410
locke-lunargd556cc32019-09-17 01:21:23 -06001411 // Store queue family data
1412 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1413 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001414 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001415 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1416 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001417 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001418 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001419 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001420 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1421 VkQueue queue = VK_NULL_HANDLE;
1422 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1423 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1424 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1425 get_info.flags = queue_info.flags;
1426 get_info.queueFamilyIndex = queue_info.queue_family_index;
1427 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001428 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001429 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001430 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001431 }
1432 assert(queue != VK_NULL_HANDLE);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001433 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001434 }
locke-lunargd556cc32019-09-17 01:21:23 -06001435 }
1436 }
1437}
1438
1439void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1440 if (!device) return;
1441
Jeremy Gebbend177d922021-10-28 13:42:10 -06001442 command_pool_map_.clear();
1443 assert(command_buffer_map_.empty());
1444 pipeline_map_.clear();
1445 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001446
1447 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001448 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001449 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001450 assert(descriptor_set_map_.empty());
1451 desc_template_map_.clear();
1452 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001453 // Because swapchains are associated with Surfaces, which are at instance level,
1454 // they need to be explicitly destroyed here to avoid continued references to
1455 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001456 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001457 entry.second->Destroy();
1458 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001459 swapchain_map_.clear();
1460 image_view_map_.clear();
1461 image_map_.clear();
1462 buffer_view_map_.clear();
1463 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001464 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001465 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001466}
1467
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001468void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1469 VkFence fence, VkResult result) {
1470 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001471 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001472
Jeremy Gebben57642982021-09-14 14:14:55 -06001473 uint64_t early_retire_seq = 0;
1474
1475 if (submitCount == 0) {
1476 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001477 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001478 early_retire_seq = queue_state->Submit(std::move(submission));
1479 }
locke-lunargd556cc32019-09-17 01:21:23 -06001480
1481 // Now process each individual submit
1482 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001483 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001484 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001485 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001486 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001487 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001488 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1489 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1490 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1491 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001492 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001493 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001494
locke-lunargd556cc32019-09-17 01:21:23 -06001495 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001496 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001497 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1498 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1499 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1500 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001501 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001502 }
1503
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001504 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001505 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001506
locke-lunargd556cc32019-09-17 01:21:23 -06001507 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001508 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1509 if (cb_state) {
1510 submission.AddCommandBuffer(std::move(cb_state));
1511 }
locke-lunargd556cc32019-09-17 01:21:23 -06001512 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001513 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001514 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001515 }
1516 auto submit_seq = queue_state->Submit(std::move(submission));
1517 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001518 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001519
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001520 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001521 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001522 }
1523}
1524
Tony-LunarG26fe2842021-11-16 14:07:59 -07001525void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1526 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001527 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001528 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001529 uint64_t early_retire_seq = 0;
1530 if (submitCount == 0) {
1531 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001532 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001533 early_retire_seq = queue_state->Submit(std::move(submission));
1534 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001535
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001536 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1537 CB_SUBMISSION submission;
1538 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001539 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1540 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001541 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001542 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001543 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1544 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001545 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001546 }
1547 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1548 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1549
1550 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001551 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001552 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001553 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001554 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001555 }
1556 auto submit_seq = queue_state->Submit(std::move(submission));
1557 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001558 }
locke-lunargd556cc32019-09-17 01:21:23 -06001559 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001560 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001561 }
1562}
1563
Tony-LunarG26fe2842021-11-16 14:07:59 -07001564void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1565 VkFence fence, VkResult result) {
1566 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1567}
1568
1569void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1570 VkFence fence, VkResult result) {
1571 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1572}
1573
locke-lunargd556cc32019-09-17 01:21:23 -06001574void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1575 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1576 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001577 if (VK_SUCCESS != result) {
1578 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001579 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001580 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1581 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1582 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1583
1584 layer_data::optional<DedicatedBinding> dedicated_binding;
1585
1586 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1587 if (dedicated) {
1588 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001589 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001590 assert(buffer_state);
1591 if (!buffer_state) {
1592 return;
1593 }
1594 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1595 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001596 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001597 assert(image_state);
1598 if (!image_state) {
1599 return;
1600 }
1601 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1602 }
1603 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001604 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1605 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001606 return;
1607}
1608
1609void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001610 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001611 if (mem_info) {
1612 fake_memory.Free(mem_info->fake_base_address);
1613 }
1614 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001615}
1616
1617void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1618 VkFence fence, VkResult result) {
1619 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001620 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001621
Jeremy Gebben57642982021-09-14 14:14:55 -06001622 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001623
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001624 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1625 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001626 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001627 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1628 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1629 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001630 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001631 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001632 if (buffer_state && mem_state) {
1633 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1634 }
locke-lunargd556cc32019-09-17 01:21:23 -06001635 }
1636 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001637 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1638 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1639 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001640 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001641 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001642 if (image_state && mem_state) {
1643 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1644 }
locke-lunargd556cc32019-09-17 01:21:23 -06001645 }
1646 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001647 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1648 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1649 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001650 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1651 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001652 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001653 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001654 if (image_state && mem_state) {
1655 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1656 }
locke-lunargd556cc32019-09-17 01:21:23 -06001657 }
1658 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001659 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001660 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001661 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001662 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001663 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001664 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001665 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001666 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001667 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001668 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001669 auto submit_seq = queue_state->Submit(std::move(submission));
1670 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001671 }
1672
1673 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001674 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001675 }
1676}
1677
1678void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1679 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1680 VkResult result) {
1681 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001682 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001683}
1684
Mike Schuchardt2df08912020-12-15 16:28:09 -08001685void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1686 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001687 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1688 if (semaphore_state) {
1689 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001690 }
1691}
1692
Mike Schuchardt2df08912020-12-15 16:28:09 -08001693void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001694 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001695 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001696 if (semaphore_state) {
1697 semaphore_state->RetireTimeline(pSignalInfo->value);
1698 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001699}
1700
locke-lunargd556cc32019-09-17 01:21:23 -06001701void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001702 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001703 if (mem_info) {
1704 mem_info->mapped_range.offset = offset;
1705 mem_info->mapped_range.size = size;
1706 mem_info->p_driver_data = *ppData;
1707 }
1708}
1709
locke-lunargd556cc32019-09-17 01:21:23 -06001710void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1711 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1712 if (VK_SUCCESS != result) return;
1713
1714 // When we know that all fences are complete we can clean/remove their CBs
1715 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1716 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001717 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001718 if (fence_state) {
1719 fence_state->Retire();
1720 }
locke-lunargd556cc32019-09-17 01:21:23 -06001721 }
1722 }
1723 // NOTE : Alternate case not handled here is when some fences have completed. In
1724 // this case for app to guarantee which fences completed it will have to call
1725 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1726}
1727
John Zulauff89de662020-04-13 18:57:34 -06001728void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1729 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001730 if (VK_SUCCESS != result) return;
1731
Jeremy Gebben15332642021-12-15 19:33:15 -07001732 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1733 // the application calls vkGetSemaphoreCounterValue() on each of them.
1734 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1735 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1736 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1737 if (semaphore_state) {
1738 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1739 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001740 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001741 }
1742}
1743
John Zulauff89de662020-04-13 18:57:34 -06001744void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1745 VkResult result) {
1746 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1747}
1748
1749void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1750 uint64_t timeout, VkResult result) {
1751 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1752}
1753
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001754void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1755 VkResult result) {
1756 if (VK_SUCCESS != result) return;
1757
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001758 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001759 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001760 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001761 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001762}
1763
1764void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1765 VkResult result) {
1766 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1767}
1768void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1769 VkResult result) {
1770 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1771}
1772
locke-lunargd556cc32019-09-17 01:21:23 -06001773void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1774 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001775 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001776 if (fence_state) {
1777 fence_state->Retire();
1778 }
locke-lunargd556cc32019-09-17 01:21:23 -06001779}
1780
Yilong Lice03a312022-01-02 02:08:35 -08001781void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1782 if (Get<QUEUE_STATE>(queue) == nullptr) {
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001783 Add(CreateQueue(queue, queue_family_index, flags));
Yilong Lice03a312022-01-02 02:08:35 -08001784 }
1785}
1786
1787void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1788 VkQueue *pQueue) {
1789 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1790}
1791
1792void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1793 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1794}
1795
locke-lunargd556cc32019-09-17 01:21:23 -06001796void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1797 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001798 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001799 if (queue_state) {
1800 queue_state->Retire();
1801 }
locke-lunargd556cc32019-09-17 01:21:23 -06001802}
1803
1804void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1805 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001806 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001807 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001808 }
1809}
1810
1811void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001812 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001813}
1814
1815void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1816 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001817 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001818}
1819
1820void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001821 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001822}
1823
1824void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1825 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001826 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001827}
1828
locke-lunargd556cc32019-09-17 01:21:23 -06001829void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001830 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001831 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001832 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001833 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001834 if (mem_state) {
1835 buffer_state->SetMemBinding(mem_state, memoryOffset);
1836 }
locke-lunargd556cc32019-09-17 01:21:23 -06001837 }
1838}
1839
1840void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1841 VkDeviceSize memoryOffset, VkResult result) {
1842 if (VK_SUCCESS != result) return;
1843 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1844}
1845
1846void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001847 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001848 for (uint32_t i = 0; i < bindInfoCount; i++) {
1849 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1850 }
1851}
1852
1853void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001854 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001855 for (uint32_t i = 0; i < bindInfoCount; i++) {
1856 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1857 }
1858}
1859
Spencer Fricke6c127102020-04-16 06:25:20 -07001860void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001861 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001862 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001863 buffer_state->memory_requirements_checked = true;
1864 }
1865}
1866
1867void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1868 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001869 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001870}
1871
1872void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001873 const VkBufferMemoryRequirementsInfo2 *pInfo,
1874 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001875 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001876}
1877
1878void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001879 const VkBufferMemoryRequirementsInfo2 *pInfo,
1880 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001881 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001882}
1883
Spencer Fricke6c127102020-04-16 06:25:20 -07001884void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001885 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001886 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001887 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001888 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001889 if (plane_info != nullptr) {
1890 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001891 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001892 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001893 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001894 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001895 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001896 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001897 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001898 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001899 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001900 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001901 }
locke-lunargd556cc32019-09-17 01:21:23 -06001902 }
1903}
1904
1905void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1906 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001907 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001908}
1909
1910void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1911 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001912 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001913}
1914
1915void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1916 const VkImageMemoryRequirementsInfo2 *pInfo,
1917 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001918 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001919}
1920
locke-lunargd556cc32019-09-17 01:21:23 -06001921void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1922 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1923 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001924 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001925 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001926}
1927
1928void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001929 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1930 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001931 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001932 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001933}
1934
1935void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001936 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1937 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001938 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001939 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001940}
1941
1942void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1943 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001944 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001945}
1946
1947void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1948 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001949 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001950}
1951
1952void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1953 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001954 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001955}
1956
1957void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1958 const VkAllocationCallbacks *pAllocator) {
1959 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001960 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001961 // Any bound cmd buffers are now invalid
1962 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001963 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1964 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1965 custom_border_color_sampler_count--;
1966 }
locke-lunargd556cc32019-09-17 01:21:23 -06001967 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001968 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001969}
1970
1971void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1972 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001973 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001974}
1975
1976void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1977 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001978 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001979}
1980
locke-lunargd556cc32019-09-17 01:21:23 -06001981void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1982 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001983 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1984 if (pool) {
1985 pool->Free(commandBufferCount, pCommandBuffers);
1986 }
locke-lunargd556cc32019-09-17 01:21:23 -06001987}
1988
1989void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1990 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1991 VkResult result) {
1992 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001993 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001994 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001995}
1996
1997void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1998 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1999 VkResult result) {
2000 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002001
2002 uint32_t index_count = 0, n_perf_pass = 0;
2003 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002004 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002005 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002006 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002007
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002008 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002009 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2010 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2011 switch (counter.scope) {
2012 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002013 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002014 break;
2015 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002016 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002017 break;
2018 default:
2019 break;
2020 }
2021 }
2022
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002023 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002024 }
2025
Jeremy Gebben082a9832021-10-28 13:40:11 -06002026 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 -06002027
locke-lunargd556cc32019-09-17 01:21:23 -06002028}
2029
2030void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2031 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002032 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002033}
2034
2035void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2036 VkCommandPoolResetFlags flags, VkResult result) {
2037 if (VK_SUCCESS != result) return;
2038 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002039 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2040 if (pool) {
2041 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002042 }
2043}
2044
2045void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2046 VkResult result) {
2047 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002048 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002049 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002050 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002051 }
2052 }
2053}
2054
locke-lunargd556cc32019-09-17 01:21:23 -06002055void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2056 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002057 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002058}
2059
2060void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2061 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002062 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002063}
2064
2065void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2066 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2067 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002068 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002069}
2070
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002071std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2072 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2073 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2074 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2075}
2076
locke-lunargd556cc32019-09-17 01:21:23 -06002077bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2078 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2079 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002080 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002081 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002082 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2083 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2084 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2085 cgpl_state->pipe_state.reserve(count);
2086 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002087 const auto &create_info = pCreateInfos[i];
2088 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2089 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2090
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002091 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002092 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002093 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002094 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2095 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002096 } else {
2097 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2098 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2099 if (!is_graphics_lib && !has_link_info) {
2100 skip = true;
2101 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002102 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002103 cgpl_state->pipe_state.push_back(
2104 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002105 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002106 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002107}
2108
2109void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2110 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2111 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2112 VkResult result, void *cgpl_state_data) {
2113 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2114 // This API may create pipelines regardless of the return value
2115 for (uint32_t i = 0; i < count; i++) {
2116 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002117 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002118 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002119 }
2120 }
2121 cgpl_state->pipe_state.clear();
2122}
2123
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002124std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2125 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2126 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2127}
2128
locke-lunargd556cc32019-09-17 01:21:23 -06002129bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2130 const VkComputePipelineCreateInfo *pCreateInfos,
2131 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002132 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002133 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2134 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2135 ccpl_state->pipe_state.reserve(count);
2136 for (uint32_t i = 0; i < count; i++) {
2137 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002138 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002139 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002140 }
2141 return false;
2142}
2143
2144void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2145 const VkComputePipelineCreateInfo *pCreateInfos,
2146 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2147 VkResult result, void *ccpl_state_data) {
2148 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2149
2150 // This API may create pipelines regardless of the return value
2151 for (uint32_t i = 0; i < count; i++) {
2152 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002153 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002154 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002155 }
2156 }
2157 ccpl_state->pipe_state.clear();
2158}
2159
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002160std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2161 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2162 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2163}
2164
locke-lunargd556cc32019-09-17 01:21:23 -06002165bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2166 uint32_t count,
2167 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2168 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002169 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002170 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2171 crtpl_state->pipe_state.reserve(count);
2172 for (uint32_t i = 0; i < count; i++) {
2173 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002174 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002175 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002176 }
2177 return false;
2178}
2179
2180void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2181 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2182 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2183 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2184 // This API may create pipelines regardless of the return value
2185 for (uint32_t i = 0; i < count; i++) {
2186 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002187 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002188 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002189 }
2190 }
2191 crtpl_state->pipe_state.clear();
2192}
2193
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002194std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2195 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2196 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2197}
2198
sourav parmarcd5fb182020-07-17 12:58:44 -07002199bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2200 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002201 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2202 const VkAllocationCallbacks *pAllocator,
2203 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002204 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002205 crtpl_state->pipe_state.reserve(count);
2206 for (uint32_t i = 0; i < count; i++) {
2207 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002208 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002209 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002210 }
2211 return false;
2212}
2213
sourav parmarcd5fb182020-07-17 12:58:44 -07002214void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2215 VkPipelineCache pipelineCache, uint32_t count,
2216 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2217 const VkAllocationCallbacks *pAllocator,
2218 VkPipeline *pPipelines, VkResult result,
2219 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002220 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002221 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002222 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002223
2224 if (!operation_is_deferred) {
2225 for (uint32_t i = 0; i < count; i++) {
2226 if (pPipelines[i] != VK_NULL_HANDLE) {
2227 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2228 Add(std::move((crtpl_state->pipe_state)[i]));
2229 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002230 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002231 } else {
2232 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2233 if (wrap_handles) {
2234 deferredOperation = layer_data->Unwrap(deferredOperation);
2235 }
2236 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2237 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2238 if (find_res->first) {
2239 cleanup_fn = std::move(find_res->second);
2240 }
2241 auto &pipeline_states = crtpl_state->pipe_state;
2242 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2243 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2244 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2245 pipeline_states[i]->SetHandle(pipelines[i]);
2246 this->Add(std::move(pipeline_states[i]));
2247 }
2248 });
2249 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002250 }
2251 crtpl_state->pipe_state.clear();
2252}
2253
locke-lunargd556cc32019-09-17 01:21:23 -06002254void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2255 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2256 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002257 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002258 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2259 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002260 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002261 }
locke-lunargd556cc32019-09-17 01:21:23 -06002262}
2263
2264void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2265 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2266 const VkAllocationCallbacks *pAllocator,
2267 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2268 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002269 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002270}
2271
locke-lunargd556cc32019-09-17 01:21:23 -06002272void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2273 const VkAllocationCallbacks *pAllocator,
2274 VkPipelineLayout *pPipelineLayout, VkResult result) {
2275 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002276 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002277}
2278
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002279std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2280 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2281 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2282}
2283
locke-lunargd556cc32019-09-17 01:21:23 -06002284void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2285 const VkAllocationCallbacks *pAllocator,
2286 VkDescriptorPool *pDescriptorPool, VkResult result) {
2287 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002288 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002289}
2290
2291void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2292 VkDescriptorPoolResetFlags flags, VkResult result) {
2293 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002294 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2295 if (pool) {
2296 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002297 }
locke-lunargd556cc32019-09-17 01:21:23 -06002298}
2299
2300bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2301 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002302 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002303 // Always update common data
2304 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2305 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2306 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2307
2308 return false;
2309}
2310
2311// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2312void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2313 VkDescriptorSet *pDescriptorSets, VkResult result,
2314 void *ads_state_data) {
2315 if (VK_SUCCESS != result) return;
2316 // All the updates are contained in a single cvdescriptorset function
2317 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2318 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002319 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2320 if (pool_state) {
2321 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2322 }
locke-lunargd556cc32019-09-17 01:21:23 -06002323}
2324
2325void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2326 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002327 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2328 if (pool_state) {
2329 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002330 }
2331}
2332
2333void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2334 const VkWriteDescriptorSet *pDescriptorWrites,
2335 uint32_t descriptorCopyCount,
2336 const VkCopyDescriptorSet *pDescriptorCopies) {
2337 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2338 pDescriptorCopies);
2339}
2340
2341void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002342 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002343 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002344 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002345 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002346 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002347 }
2348}
2349
locke-lunargd556cc32019-09-17 01:21:23 -06002350void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2351 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002352 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002353 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002354
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002355 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002356}
2357
2358void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002359 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002360 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002361
2362 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002363}
2364
2365void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2366 VkResult result) {
2367 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002368 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2369 if (cb_state) {
2370 cb_state->Reset();
2371 }
locke-lunargd556cc32019-09-17 01:21:23 -06002372 }
2373}
2374
2375CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2376 // initially assume everything is static state
2377 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2378
2379 if (ds) {
2380 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002381 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002382 }
2383 }
locke-lunargd556cc32019-09-17 01:21:23 -06002384 return flags;
2385}
2386
2387// Validation cache:
2388// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002389
2390void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2391 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002392 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002393 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002394 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002395
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002396 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002397 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002398 const auto *raster_state = pipe_state->RasterizationState();
2399 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002400 const auto *viewport_state = pipe_state->ViewportState();
2401 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002402 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002403 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002404 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002405 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002406
2407 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002408 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2409 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002410 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002411 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002412 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002413 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002414 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002415 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002416
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002417 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002418 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2419 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2420 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002421 if (!has_dynamic_viewport_count) {
2422 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002423 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002424 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2425 // should become = ~uint32_t(0) if the other interpretation is correct.
2426 }
2427 }
2428 if (!has_dynamic_scissor_count) {
2429 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002430 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002431 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2432 // should become = ~uint32_t(0) if the other interpretation is correct.
2433 }
2434 }
locke-lunargd556cc32019-09-17 01:21:23 -06002435 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002436 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002437 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002438 if (!disabled[command_buffer_state]) {
2439 cb_state->AddChild(pipe_state);
2440 }
locke-lunargd556cc32019-09-17 01:21:23 -06002441}
2442
2443void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2444 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002445 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002446 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002447 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2448 cb_state->viewportMask |= bits;
2449 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002450
2451 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2452 for (size_t i = 0; i < viewportCount; ++i) {
2453 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2454 }
locke-lunargd556cc32019-09-17 01:21:23 -06002455}
2456
2457void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2458 uint32_t exclusiveScissorCount,
2459 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002460 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002461 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002462 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2463 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002464}
2465
2466void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2467 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002468 if (disabled[command_buffer_state]) return;
2469
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002470 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002471 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002472
2473 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002474 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002475 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002476 }
2477}
2478
2479void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2480 uint32_t viewportCount,
2481 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002482 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002483 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002484 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2485 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002486}
2487
2488void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2489 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2490 const VkAllocationCallbacks *pAllocator,
2491 VkAccelerationStructureNV *pAccelerationStructure,
2492 VkResult result) {
2493 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002494 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002495}
2496
Jeff Bolz95176d02020-04-01 00:36:16 -05002497void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2498 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2499 const VkAllocationCallbacks *pAllocator,
2500 VkAccelerationStructureKHR *pAccelerationStructure,
2501 VkResult result) {
2502 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002503 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2504 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002505}
2506
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002507void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2508 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2509 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2510 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2511 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002512 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002513 if (dst_as_state != nullptr) {
2514 dst_as_state->Build(&pInfos[i]);
2515 }
2516 }
2517}
2518
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002519// helper method for device side acceleration structure builds
2520void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2521 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2522 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2523 if (dst_as_state) {
2524 dst_as_state->Build(&info);
2525 }
2526 if (disabled[command_buffer_state]) {
2527 return;
2528 }
2529 if (dst_as_state) {
2530 cb_state.AddChild(dst_as_state);
2531 }
2532 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2533 if (src_as_state) {
2534 cb_state.AddChild(src_as_state);
2535 }
2536 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2537 if (scratch_buffer) {
2538 cb_state.AddChild(scratch_buffer);
2539 }
2540
2541 for (uint32_t i = 0; i < info.geometryCount; i++) {
2542 // only one of pGeometries and ppGeometries can be non-null
2543 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2544 switch (geom.geometryType) {
2545 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2546 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2547 if (vertex_buffer) {
2548 cb_state.AddChild(vertex_buffer);
2549 }
2550 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2551 if (index_buffer) {
2552 cb_state.AddChild(index_buffer);
2553 }
2554 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2555 if (transform_buffer) {
2556 cb_state.AddChild(transform_buffer);
2557 }
2558 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2559 if (motion_data) {
2560 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2561 if (motion_buffer) {
2562 cb_state.AddChild(motion_buffer);
2563 }
2564 }
2565 } break;
2566 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2567 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2568 if (data_buffer) {
2569 cb_state.AddChild(data_buffer);
2570 }
2571 } break;
2572 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2573 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2574 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2575 // easily ensure that's true.
2576 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2577 if (data_buffer) {
2578 cb_state.AddChild(data_buffer);
2579 }
2580 } break;
2581 default:
2582 break;
2583 }
2584 }
2585}
2586
sourav parmarcd5fb182020-07-17 12:58:44 -07002587void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2588 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2589 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002590 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002591 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002592 return;
2593 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002594 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002595 for (uint32_t i = 0; i < infoCount; i++) {
2596 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002597 }
2598 cb_state->hasBuildAccelerationStructureCmd = true;
2599}
2600
2601void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2602 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2603 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2604 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002605 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2606 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002607 return;
2608 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002609 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002610 for (uint32_t i = 0; i < infoCount; i++) {
2611 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002612 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002613 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2614 if (indirect_buffer) {
2615 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002616 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002617 }
2618 }
2619 cb_state->hasBuildAccelerationStructureCmd = true;
2620}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002621
locke-lunargd556cc32019-09-17 01:21:23 -06002622void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002623 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002624 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002625 if (as_state != nullptr) {
2626 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002627 as_state->memory_requirements_checked = true;
2628 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002629 as_state->build_scratch_memory_requirements_checked = true;
2630 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002631 as_state->update_scratch_memory_requirements_checked = true;
2632 }
2633 }
2634}
2635
sourav parmarcd5fb182020-07-17 12:58:44 -07002636void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2637 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002638 if (VK_SUCCESS != result) return;
2639 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002640 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002641
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002642 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002643 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002644 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002645 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002646 if (mem_state) {
2647 as_state->SetMemBinding(mem_state, info.memoryOffset);
2648 }
locke-lunargd556cc32019-09-17 01:21:23 -06002649
2650 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002651 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002652 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002653 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2654 }
2655 }
2656 }
2657}
2658
2659void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2660 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2661 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002662 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2663 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002664 return;
2665 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002666 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002667
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002668 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002669 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002670 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002671 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002672 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002673 }
locke-lunargd556cc32019-09-17 01:21:23 -06002674 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002675 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002676 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002677 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002678 cb_state->AddChild(src_as_state);
2679 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002680 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2681 if (instance_buffer) {
2682 cb_state->AddChild(instance_buffer);
2683 }
2684 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2685 if (scratch_buffer) {
2686 cb_state->AddChild(scratch_buffer);
2687 }
2688
2689 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2690 const auto& geom = pInfo->pGeometries[i];
2691
2692 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2693 if (vertex_buffer) {
2694 cb_state->AddChild(vertex_buffer);
2695 }
2696 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2697 if (index_buffer) {
2698 cb_state->AddChild(index_buffer);
2699 }
2700 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2701 if (transform_buffer) {
2702 cb_state->AddChild(transform_buffer);
2703 }
2704
2705 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2706 if (aabb_buffer) {
2707 cb_state->AddChild(aabb_buffer);
2708 }
2709 }
2710
locke-lunargd556cc32019-09-17 01:21:23 -06002711 }
2712 cb_state->hasBuildAccelerationStructureCmd = true;
2713}
2714
2715void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2716 VkAccelerationStructureNV dst,
2717 VkAccelerationStructureNV src,
2718 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002719 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002720 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002721 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2722 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002723 if (!disabled[command_buffer_state]) {
2724 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2725 }
locke-lunargd556cc32019-09-17 01:21:23 -06002726 if (dst_as_state != nullptr && src_as_state != nullptr) {
2727 dst_as_state->built = true;
2728 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002729 }
2730 }
2731}
2732
Jeff Bolz95176d02020-04-01 00:36:16 -05002733void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2734 VkAccelerationStructureKHR accelerationStructure,
2735 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002736 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002737}
2738
Jeff Bolz95176d02020-04-01 00:36:16 -05002739void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2740 VkAccelerationStructureNV accelerationStructure,
2741 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002742 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002743}
2744
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002745void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2746 uint32_t viewportCount,
2747 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002748 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002749 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002750}
2751
locke-lunargd556cc32019-09-17 01:21:23 -06002752void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002753 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002754 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002755}
2756
2757void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2758 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002759 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002760 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002761}
2762
2763void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2764 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002765 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002766 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002767}
2768
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002769void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2770 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002771 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002772 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002773 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2774 cb_state->scissorMask |= bits;
2775 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002776}
2777
locke-lunargd556cc32019-09-17 01:21:23 -06002778void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002779 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002780 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002781}
2782
2783void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2784 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002785 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002786 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002787}
2788
2789void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2790 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002791 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002792 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002793}
2794
2795void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2796 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002797 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002798 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002799}
2800
2801void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2802 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002803 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002804 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002805}
2806
locke-lunargd556cc32019-09-17 01:21:23 -06002807// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2808void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2809 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2810 uint32_t firstSet, uint32_t setCount,
2811 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2812 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002813 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002814 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002815 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002816 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002817
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002818 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2819 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002820}
2821
locke-lunargd556cc32019-09-17 01:21:23 -06002822void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2823 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2824 uint32_t set, uint32_t descriptorWriteCount,
2825 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002826 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002827 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002828 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002829}
2830
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002831void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2832 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2833 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002834 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2835 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002836 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002837 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2838 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002839
2840 auto &push_constant_data = cb_state->push_constant_data;
2841 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2842 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002843 cb_state->push_constant_pipeline_layout_set = layout;
2844
2845 auto flags = stageFlags;
2846 uint32_t bit_shift = 0;
2847 while (flags) {
2848 if (flags & 1) {
2849 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2850 const auto it = cb_state->push_constant_data_update.find(flag);
2851
2852 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002853 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002854 }
2855 }
2856 flags = flags >> 1;
2857 ++bit_shift;
2858 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002859 }
2860}
2861
locke-lunargd556cc32019-09-17 01:21:23 -06002862void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2863 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002864 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002865
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002866 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002867 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002868 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002869 cb_state->index_buffer_binding.offset = offset;
2870 cb_state->index_buffer_binding.index_type = indexType;
2871 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002872 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002873 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002874 }
locke-lunargd556cc32019-09-17 01:21:23 -06002875}
2876
2877void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2878 uint32_t bindingCount, const VkBuffer *pBuffers,
2879 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002880 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002881 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002882
2883 uint32_t end = firstBinding + bindingCount;
2884 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2885 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2886 }
2887
2888 for (uint32_t i = 0; i < bindingCount; ++i) {
2889 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002890 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002891 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002892 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2893 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002894 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002895 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002896 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002897 }
locke-lunargd556cc32019-09-17 01:21:23 -06002898 }
2899}
2900
2901void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2902 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002903 if (disabled[command_buffer_state]) return;
2904
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002905 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002906 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002907}
2908
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002909void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2910 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002911 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002912 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002913}
2914
2915void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2916 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002917 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002918 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2919
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002920 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2921 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002922}
2923
Tony-LunarGc43525f2021-11-15 16:12:38 -07002924void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2925 const VkDependencyInfo* pDependencyInfo) {
2926 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2927 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2928
2929 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2930 cb_state->RecordBarriers(*pDependencyInfo);
2931}
2932
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002933void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2934 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002935 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002936 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002937}
2938
2939void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2940 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002941 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002942 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002943}
2944
Tony-LunarGa2662db2021-11-16 07:26:24 -07002945void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2946 VkPipelineStageFlags2 stageMask) {
2947 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2948 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2949}
2950
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002951void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2952 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2953 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2954 uint32_t bufferMemoryBarrierCount,
2955 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2956 uint32_t imageMemoryBarrierCount,
2957 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002958 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2959 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002960 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2961 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002962}
2963
2964void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2965 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002966 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002967 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002968 const auto &dep_info = pDependencyInfos[i];
2969 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2970 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2971 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002972 }
2973}
2974
Tony-LunarG1364cf52021-11-17 16:10:11 -07002975void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2976 const VkDependencyInfo *pDependencyInfos) {
2977 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2978 for (uint32_t i = 0; i < eventCount; i++) {
2979 const auto &dep_info = pDependencyInfos[i];
2980 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2981 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2982 cb_state->RecordBarriers(dep_info);
2983 }
2984}
2985
Jeremy Gebben79649152021-06-22 14:46:24 -06002986void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2987 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2988 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2989 uint32_t bufferMemoryBarrierCount,
2990 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2991 uint32_t imageMemoryBarrierCount,
2992 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002993 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002994 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2995 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2996 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002997}
2998
2999void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3000 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003001 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003002 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3003 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003004}
3005
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07003006void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
3007 const VkDependencyInfo *pDependencyInfo) {
3008 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3009 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
3010 cb_state->RecordBarriers(*pDependencyInfo);
3011}
3012
locke-lunargd556cc32019-09-17 01:21:23 -06003013void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3014 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003015 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003016
locke-lunargd556cc32019-09-17 01:21:23 -06003017 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003018 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003019 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003020 if (!disabled[query_validation]) {
3021 cb_state->BeginQuery(query);
3022 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003023 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003024 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003025 cb_state->AddChild(pool_state);
3026 }
locke-lunargd556cc32019-09-17 01:21:23 -06003027}
3028
3029void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003030 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003031 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003032 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003033 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003034 if (!disabled[query_validation]) {
3035 cb_state->EndQuery(query_obj);
3036 }
3037 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003038 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003039 cb_state->AddChild(pool_state);
3040 }
locke-lunargd556cc32019-09-17 01:21:23 -06003041}
3042
3043void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3044 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003045 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003046 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003047
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003048 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003049 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003050
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003051 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003052 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003053 cb_state->AddChild(pool_state);
3054 }
locke-lunargd556cc32019-09-17 01:21:23 -06003055}
3056
3057void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3058 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3059 VkDeviceSize dstOffset, VkDeviceSize stride,
3060 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003061 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3062
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003063 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003064 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003065 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003066 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003067 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003068 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003069}
3070
3071void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3072 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003073 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003074 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003075}
3076
3077void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3078 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3079 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003080 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003081 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003082}
3083
Tony-LunarGde9936b2021-11-17 15:34:11 -07003084void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3085 VkQueryPool queryPool, uint32_t slot) {
3086 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3087 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3088}
3089
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003090void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3091 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3092 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3093 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003094 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003095 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003096 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003097 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003098 cb_state->AddChild(pool_state);
3099 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003100 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003101}
3102
locke-lunargd556cc32019-09-17 01:21:23 -06003103void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3104 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3105 VkResult result) {
3106 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003107
Jeremy Gebben88f58142021-06-01 10:07:52 -06003108 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003109 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003110 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003111
locke-lunargd556cc32019-09-17 01:21:23 -06003112 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003113 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003114 }
3115 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003116
Jeremy Gebben9f537102021-10-05 16:37:12 -06003117 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003118 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003119}
3120
locke-lunargd556cc32019-09-17 01:21:23 -06003121void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3122 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3123 VkResult result) {
3124 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003125 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003126}
3127
Mike Schuchardt2df08912020-12-15 16:28:09 -08003128void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003129 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3130 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003131 if (VK_SUCCESS != result) return;
3132
Jeremy Gebben082a9832021-10-28 13:40:11 -06003133 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003134}
3135
Mike Schuchardt2df08912020-12-15 16:28:09 -08003136void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003137 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3138 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003139 if (VK_SUCCESS != result) return;
3140
Jeremy Gebben082a9832021-10-28 13:40:11 -06003141 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003142}
3143
locke-lunargd556cc32019-09-17 01:21:23 -06003144void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3145 const VkRenderPassBeginInfo *pRenderPassBegin,
3146 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003147 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003148 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003149}
3150
3151void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3152 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003153 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003154 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003155 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003156}
3157
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003158void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3159 uint32_t counterBufferCount,
3160 const VkBuffer *pCounterBuffers,
3161 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003162 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003163
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003164 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003165 cb_state->transform_feedback_active = true;
3166}
3167
3168void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3169 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3170 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003171 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003172
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003173 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003174 cb_state->transform_feedback_active = false;
3175}
3176
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003177void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3178 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003179 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003180
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003181 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003182 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003183 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3184 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003185}
3186
3187void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003188 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003189
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003190 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003191 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003192 cb_state->conditional_rendering_inside_render_pass = false;
3193 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003194}
3195
amhagana448ea52021-11-02 14:09:14 -04003196void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003197 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003198 cb_state->activeRenderPass = nullptr;
3199}
3200
3201void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3202 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003203 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003204 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3205}
3206
Tony-LunarG40b33882021-12-02 12:40:11 -07003207void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3208 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3209 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3210}
3211
amhagana448ea52021-11-02 14:09:14 -04003212void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3213 RecordCmdEndRenderingRenderPassState(commandBuffer);
3214}
3215
Tony-LunarG40b33882021-12-02 12:40:11 -07003216void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3217 RecordCmdEndRenderingRenderPassState(commandBuffer);
3218}
3219
Tony-LunarG977448c2019-12-02 14:52:02 -07003220void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3221 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003222 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003223 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003224 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003225}
3226
locke-lunargd556cc32019-09-17 01:21:23 -06003227void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003228 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003229 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003230}
3231
3232void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003233 const VkSubpassBeginInfo *pSubpassBeginInfo,
3234 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003235 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003236 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003237}
3238
Tony-LunarG977448c2019-12-02 14:52:02 -07003239void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003240 const VkSubpassBeginInfo *pSubpassBeginInfo,
3241 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003242 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003243 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003244}
3245
3246void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003247 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003248 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003249}
3250
3251void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003252 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003253 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003254 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003255}
3256
Tony-LunarG977448c2019-12-02 14:52:02 -07003257void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003258 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003259 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003260 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003261}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003262
locke-lunargd556cc32019-09-17 01:21:23 -06003263void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3264 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003265 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003266
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003267 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003268}
3269
3270void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3271 VkFlags flags, void **ppData, VkResult result) {
3272 if (VK_SUCCESS != result) return;
3273 RecordMappedMemory(mem, offset, size, ppData);
3274}
3275
3276void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003277 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003278 if (mem_info) {
3279 mem_info->mapped_range = MemRange();
3280 mem_info->p_driver_data = nullptr;
3281 }
3282}
3283
3284void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003285 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003286 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003287 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3288 // See: VUID-vkGetImageSubresourceLayout-image-01895
3289 image_state->fragment_encoder =
3290 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003291 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003292 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003293 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003294 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003295 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003296
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003297 if (!swapchain_image.fake_base_address) {
3298 auto size = image_state->fragment_encoder->TotalSize();
3299 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003300 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003301 // All images bound to this swapchain and index are aliases
3302 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003303 }
3304 } else {
3305 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003306 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003307 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003308 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003309 }
locke-lunargd556cc32019-09-17 01:21:23 -06003310 }
locke-lunargd556cc32019-09-17 01:21:23 -06003311 }
3312}
3313
3314void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3315 VkDeviceSize memoryOffset, VkResult result) {
3316 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003317 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003318 bind_info.image = image;
3319 bind_info.memory = mem;
3320 bind_info.memoryOffset = memoryOffset;
3321 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003322}
3323
3324void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003325 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003326 if (VK_SUCCESS != result) return;
3327 for (uint32_t i = 0; i < bindInfoCount; i++) {
3328 UpdateBindImageMemoryState(pBindInfos[i]);
3329 }
3330}
3331
3332void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003333 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003334 if (VK_SUCCESS != result) return;
3335 for (uint32_t i = 0; i < bindInfoCount; i++) {
3336 UpdateBindImageMemoryState(pBindInfos[i]);
3337 }
3338}
3339
3340void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003341 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003342 if (event_state) {
3343 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3344 }
locke-lunargd556cc32019-09-17 01:21:23 -06003345}
3346
3347void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3348 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3349 VkResult result) {
3350 if (VK_SUCCESS != result) return;
3351 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3352 pImportSemaphoreFdInfo->flags);
3353}
3354
3355void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003356 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003357 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003358 if (semaphore_state) {
3359 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003360 }
3361}
3362
3363#ifdef VK_USE_PLATFORM_WIN32_KHR
3364void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3365 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3366 if (VK_SUCCESS != result) return;
3367 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3368 pImportSemaphoreWin32HandleInfo->flags);
3369}
3370
3371void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3372 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3373 HANDLE *pHandle, VkResult result) {
3374 if (VK_SUCCESS != result) return;
3375 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3376}
3377
3378void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3379 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3380 if (VK_SUCCESS != result) return;
3381 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3382 pImportFenceWin32HandleInfo->flags);
3383}
3384
3385void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3386 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3387 HANDLE *pHandle, VkResult result) {
3388 if (VK_SUCCESS != result) return;
3389 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3390}
3391#endif
3392
3393void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3394 VkResult result) {
3395 if (VK_SUCCESS != result) return;
3396 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3397}
3398
Mike Schuchardt2df08912020-12-15 16:28:09 -08003399void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3400 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003401 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003402
3403 if (fence_node) {
3404 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003405 }
3406}
3407
3408void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3409 VkResult result) {
3410 if (VK_SUCCESS != result) return;
3411 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3412}
3413
Mike Schuchardt2df08912020-12-15 16:28:09 -08003414void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003415 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003416 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003417 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003418 }
3419}
3420
3421void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3422 VkResult result) {
3423 if (VK_SUCCESS != result) return;
3424 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3425}
3426
3427void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3428 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3429 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003430 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003431}
3432
3433void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003434 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003435 SWAPCHAIN_NODE *old_swapchain_state) {
3436 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003437 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003438 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003439 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003440 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3441 surface_state->AddParent(swapchain.get());
3442 surface_state->swapchain = swapchain.get();
3443 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003444 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003445 } else {
3446 surface_state->swapchain = nullptr;
3447 }
3448 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003449 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003450 if (old_swapchain_state) {
3451 old_swapchain_state->retired = true;
3452 }
3453 return;
3454}
3455
3456void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3457 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3458 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003459 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003460 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003461 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003462}
3463
3464void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3465 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003466 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003467}
3468
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003469void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3470 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3471 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3472 VkResult result) {
3473 if (VK_SUCCESS != result) return;
3474 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003475 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003476}
3477
locke-lunargd556cc32019-09-17 01:21:23 -06003478void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003479 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003480 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003481 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3482 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3483 if (semaphore_state) {
3484 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003485 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003486 }
3487
3488 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3489 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3490 // 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
3491 // confused itself just as much.
3492 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3493 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3494 // Mark the image as having been released to the WSI
3495 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3496 if (swapchain_data) {
3497 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3498 if (present_id_info) {
3499 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3500 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3501 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003502 }
3503 }
locke-lunargd556cc32019-09-17 01:21:23 -06003504 }
locke-lunargd556cc32019-09-17 01:21:23 -06003505}
3506
3507void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3508 const VkSwapchainCreateInfoKHR *pCreateInfos,
3509 const VkAllocationCallbacks *pAllocator,
3510 VkSwapchainKHR *pSwapchains, VkResult result) {
3511 if (pCreateInfos) {
3512 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003513 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003514 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003515 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3516 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003517 }
3518 }
3519}
3520
3521void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3522 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003523 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003524 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003525 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3526 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003527 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003528 }
3529
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003530 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003531 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003532 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3533 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003534 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003535 }
3536
3537 // Mark the image as acquired.
3538 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3539 if (swapchain_data) {
3540 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003541 }
3542}
3543
3544void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3545 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3546 VkResult result) {
3547 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3548 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3549}
3550
3551void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3552 uint32_t *pImageIndex, VkResult result) {
3553 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3554 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3555 pAcquireInfo->fence, pImageIndex);
3556}
3557
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003558std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3559 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3560}
3561
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003562void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3563 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3564 VkResult result) {
3565 if (result != VK_SUCCESS) {
3566 return;
3567 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003568 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003569 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003570 // this can fail if the allocator fails
3571 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3572 if (result != VK_SUCCESS) {
3573 return;
3574 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003575 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003576 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3577 if (result != VK_SUCCESS) {
3578 return;
3579 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003580
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003581 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003582 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003583 }
3584}
3585
3586// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003587static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003588 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003589}
3590
3591void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3592 uint32_t *pQueueFamilyPropertyCount,
3593 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003594 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3595 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003596 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003597}
3598
3599void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003600 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003601 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3602 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003603 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003604}
3605
3606void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003607 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003608 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3609 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003610 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003611}
3612void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3613 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003614 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003615}
3616
Jeremy Gebben082a9832021-10-28 13:40:11 -06003617void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003618
3619void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3620 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3621 const VkAllocationCallbacks *pAllocator,
3622 VkSurfaceKHR *pSurface, VkResult result) {
3623 if (VK_SUCCESS != result) return;
3624 RecordVulkanSurface(pSurface);
3625}
3626
3627#ifdef VK_USE_PLATFORM_ANDROID_KHR
3628void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3629 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3630 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3631 VkResult result) {
3632 if (VK_SUCCESS != result) return;
3633 RecordVulkanSurface(pSurface);
3634}
3635#endif // VK_USE_PLATFORM_ANDROID_KHR
3636
3637#ifdef VK_USE_PLATFORM_IOS_MVK
3638void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3639 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3640 VkResult result) {
3641 if (VK_SUCCESS != result) return;
3642 RecordVulkanSurface(pSurface);
3643}
3644#endif // VK_USE_PLATFORM_IOS_MVK
3645
3646#ifdef VK_USE_PLATFORM_MACOS_MVK
3647void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3648 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3649 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3650 VkResult result) {
3651 if (VK_SUCCESS != result) return;
3652 RecordVulkanSurface(pSurface);
3653}
3654#endif // VK_USE_PLATFORM_MACOS_MVK
3655
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003656#ifdef VK_USE_PLATFORM_METAL_EXT
3657void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3658 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3659 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3660 VkResult result) {
3661 if (VK_SUCCESS != result) return;
3662 RecordVulkanSurface(pSurface);
3663}
3664#endif // VK_USE_PLATFORM_METAL_EXT
3665
locke-lunargd556cc32019-09-17 01:21:23 -06003666#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3667void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3668 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3669 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3670 VkResult result) {
3671 if (VK_SUCCESS != result) return;
3672 RecordVulkanSurface(pSurface);
3673}
3674#endif // VK_USE_PLATFORM_WAYLAND_KHR
3675
3676#ifdef VK_USE_PLATFORM_WIN32_KHR
3677void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3678 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3679 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3680 VkResult result) {
3681 if (VK_SUCCESS != result) return;
3682 RecordVulkanSurface(pSurface);
3683}
3684#endif // VK_USE_PLATFORM_WIN32_KHR
3685
3686#ifdef VK_USE_PLATFORM_XCB_KHR
3687void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3688 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3689 VkResult result) {
3690 if (VK_SUCCESS != result) return;
3691 RecordVulkanSurface(pSurface);
3692}
3693#endif // VK_USE_PLATFORM_XCB_KHR
3694
3695#ifdef VK_USE_PLATFORM_XLIB_KHR
3696void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3697 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3698 VkResult result) {
3699 if (VK_SUCCESS != result) return;
3700 RecordVulkanSurface(pSurface);
3701}
3702#endif // VK_USE_PLATFORM_XLIB_KHR
3703
Niklas Haas8b84af12020-04-19 22:20:11 +02003704void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3705 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3706 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3707 VkResult result) {
3708 if (VK_SUCCESS != result) return;
3709 RecordVulkanSurface(pSurface);
3710}
3711
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003712void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3713 VkSurfaceKHR surface,
3714 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3715 VkResult result) {
3716 if (VK_SUCCESS != result) return;
3717 auto surface_state = Get<SURFACE_STATE>(surface);
3718 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3719}
3720
3721void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3722 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3723 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3724 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003725
3726 if (pSurfaceInfo->surface) {
3727 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3728 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3729 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3730 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3731 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3732 assert(pd_state);
3733 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3734 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003735}
3736
3737void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3738 VkSurfaceKHR surface,
3739 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3740 VkResult result) {
3741 auto surface_state = Get<SURFACE_STATE>(surface);
3742 VkSurfaceCapabilitiesKHR caps{
3743 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3744 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3745 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3746 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3747 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3748 };
3749 surface_state->SetCapabilities(physicalDevice, caps);
3750}
3751
locke-lunargd556cc32019-09-17 01:21:23 -06003752void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3753 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3754 VkBool32 *pSupported, VkResult result) {
3755 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003756 auto surface_state = Get<SURFACE_STATE>(surface);
3757 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3758}
3759
3760void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3761 VkSurfaceKHR surface,
3762 uint32_t *pPresentModeCount,
3763 VkPresentModeKHR *pPresentModes,
3764 VkResult result) {
3765 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3766
3767 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003768 if (surface) {
3769 auto surface_state = Get<SURFACE_STATE>(surface);
3770 surface_state->SetPresentModes(physicalDevice,
3771 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3772 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3773 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3774 assert(pd_state);
3775 pd_state->surfaceless_query_state.present_modes =
3776 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3777 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003778 }
3779}
3780
3781void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3782 uint32_t *pSurfaceFormatCount,
3783 VkSurfaceFormatKHR *pSurfaceFormats,
3784 VkResult result) {
3785 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3786
3787 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003788 if (surface) {
3789 auto surface_state = Get<SURFACE_STATE>(surface);
3790 surface_state->SetFormats(physicalDevice,
3791 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3792 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3793 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3794 assert(pd_state);
3795 pd_state->surfaceless_query_state.formats =
3796 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3797 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003798 }
3799}
3800
3801void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3802 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3803 uint32_t *pSurfaceFormatCount,
3804 VkSurfaceFormat2KHR *pSurfaceFormats,
3805 VkResult result) {
3806 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3807
3808 if (pSurfaceFormats) {
3809 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003810 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3811 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3812 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003813 if (pSurfaceInfo->surface) {
3814 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3815 surface_state->SetFormats(physicalDevice, std::move(fmts));
3816 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3817 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3818 assert(pd_state);
3819 pd_state->surfaceless_query_state.formats = std::move(fmts);
3820 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003821 }
locke-lunargd556cc32019-09-17 01:21:23 -06003822}
3823
locke-lunargd556cc32019-09-17 01:21:23 -06003824void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3825 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003826 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003827 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003828 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3829}
3830
3831void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003832 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003833 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003834 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3835}
3836
3837void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3838 const VkDebugUtilsLabelEXT *pLabelInfo) {
3839 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3840
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003841 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003842 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3843 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003844 cb_state->debug_label = LoggingLabel(pLabelInfo);
3845}
3846
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003847void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3848 uint32_t queueFamilyIndex,
3849 uint32_t *pCounterCount,
3850 VkPerformanceCounterKHR *pCounters) {
3851 if (NULL == pCounters) return;
3852
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003853 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3854 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003855
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003856 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3857 queue_family_counters->counters.resize(*pCounterCount);
3858 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003859
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003860 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003861}
3862
3863void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3864 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3865 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3866 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3867 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3868}
3869
3870void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3871 VkResult result) {
3872 if (result == VK_SUCCESS) performance_lock_acquired = true;
3873}
3874
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003875void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3876 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003877 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003878 cmd_buffer.second->performance_lock_released = true;
3879 }
3880}
3881
locke-lunargd556cc32019-09-17 01:21:23 -06003882void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003883 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003884 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003885 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003886}
3887
3888void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003889 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003890 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003891 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003892}
3893
Mike Schuchardt2df08912020-12-15 16:28:09 -08003894void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3895 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003896 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003897}
3898
Mike Schuchardt2df08912020-12-15 16:28:09 -08003899void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3900 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3901 const VkAllocationCallbacks *pAllocator,
3902 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3903 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003904 if (VK_SUCCESS != result) return;
3905 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3906}
3907
3908void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003909 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3910 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003911 if (VK_SUCCESS != result) return;
3912 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3913}
3914
3915void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003916 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003917 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003918 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3919 assert(template_state);
3920 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003921 // TODO: Record template push descriptor updates
3922 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003923 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003924 }
3925 }
3926}
3927
3928void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3929 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3930 const void *pData) {
3931 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3932}
3933
3934void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003935 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003936 const void *pData) {
3937 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3938}
3939
Mike Schuchardt2df08912020-12-15 16:28:09 -08003940void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3941 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3942 VkPipelineLayout layout, uint32_t set,
3943 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003944 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003945
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003946 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003947 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003948 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003949 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003950 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003951 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003952 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003953 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003954 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003955 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003956 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3957 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003958 }
3959}
3960
3961void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3962 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003963 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003964 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003965 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003966 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003967 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003968 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003969 }
3970}
3971
3972void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3973 uint32_t *pPropertyCount,
3974 VkDisplayPlanePropertiesKHR *pProperties,
3975 VkResult result) {
3976 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3977 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3978}
3979
3980void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3981 uint32_t *pPropertyCount,
3982 VkDisplayPlaneProperties2KHR *pProperties,
3983 VkResult result) {
3984 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3985 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3986}
3987
3988void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3989 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3990 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003991 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003992 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003993 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003994}
3995
3996void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3997 uint32_t query, uint32_t index) {
3998 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003999 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004000 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004001 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06004002}
4003
4004void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
4005 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02004006 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004007
4008 if (create_info->format != VK_FORMAT_UNDEFINED) {
4009 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07004010 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004011 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
4012 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004013 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004014
Jeremy Gebben082a9832021-10-28 13:40:11 -06004015 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004016}
4017
4018void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4019 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4020 const VkAllocationCallbacks *pAllocator,
4021 VkSamplerYcbcrConversion *pYcbcrConversion,
4022 VkResult result) {
4023 if (VK_SUCCESS != result) return;
4024 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4025}
4026
4027void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4028 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4029 const VkAllocationCallbacks *pAllocator,
4030 VkSamplerYcbcrConversion *pYcbcrConversion,
4031 VkResult result) {
4032 if (VK_SUCCESS != result) return;
4033 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4034}
4035
4036void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4037 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004038 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004039}
4040
4041void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4042 VkSamplerYcbcrConversion ycbcrConversion,
4043 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004044 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004045}
4046
Tony-LunarG977448c2019-12-02 14:52:02 -07004047void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4048 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004049 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004050 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004051
4052 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004053 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004054 if (!query_pool_state) return;
4055
4056 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004057 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4058 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004059 auto query_index = firstQuery + i;
4060 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004061 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004062 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004063 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004064 }
4065 }
locke-lunargd556cc32019-09-17 01:21:23 -06004066 }
4067}
4068
Tony-LunarG977448c2019-12-02 14:52:02 -07004069void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4070 uint32_t queryCount) {
4071 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4072}
4073
4074void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4075 uint32_t queryCount) {
4076 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4077}
4078
locke-lunargd556cc32019-09-17 01:21:23 -06004079void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004080 const UPDATE_TEMPLATE_STATE *template_state,
4081 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004082 // Translate the templated update into a normal update for validation...
4083 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4084 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4085 decoded_update.desc_writes.data(), 0, NULL);
4086}
4087
4088// Update the common AllocateDescriptorSetsData
4089void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004090 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004091 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004092 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004093 if (layout) {
4094 ds_data->layout_nodes[i] = layout;
4095 // Count total descriptors required per type
4096 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4097 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004098 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4099 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004100 }
4101 }
4102 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4103 }
4104}
4105
locke-lunargd556cc32019-09-17 01:21:23 -06004106void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4107 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004108 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004109 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004110}
4111
Tony-LunarG745150c2021-07-02 15:07:31 -06004112void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4113 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4114 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004115 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004116 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004117}
4118
locke-lunargd556cc32019-09-17 01:21:23 -06004119void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4120 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4121 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004122 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004123 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004124}
4125
Tony-LunarG745150c2021-07-02 15:07:31 -06004126void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4127 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4128 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4129 const int32_t *pVertexOffset) {
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_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004132}
4133
locke-lunargd556cc32019-09-17 01:21:23 -06004134void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4135 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004136 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004137 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004138 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004139 if (!disabled[command_buffer_state]) {
4140 cb_state->AddChild(buffer_state);
4141 }
locke-lunargd556cc32019-09-17 01:21:23 -06004142}
4143
4144void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4145 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004146 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004147 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004148 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004149 if (!disabled[command_buffer_state]) {
4150 cb_state->AddChild(buffer_state);
4151 }
locke-lunargd556cc32019-09-17 01:21:23 -06004152}
4153
4154void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004155 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004156 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004157}
4158
4159void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4160 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004161 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004162 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004163 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004164 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004165 cb_state->AddChild(buffer_state);
4166 }
locke-lunargd556cc32019-09-17 01:21:23 -06004167}
4168
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004169void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4170 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004171 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004172 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4173}
4174
4175void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4176 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004177 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004178 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4179}
4180
Tony-LunarG977448c2019-12-02 14:52:02 -07004181void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4182 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004183 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004184 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004185 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004186 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004187 auto buffer_state = Get<BUFFER_STATE>(buffer);
4188 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004189 cb_state->AddChild(buffer_state);
4190 cb_state->AddChild(count_buffer_state);
4191 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004192}
4193
locke-lunargd556cc32019-09-17 01:21:23 -06004194void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4195 VkDeviceSize offset, VkBuffer countBuffer,
4196 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4197 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004198 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004199 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004200}
4201
4202void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4203 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4204 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004205 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004206 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004207}
4208
4209void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4210 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004211 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004212 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004213 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004214 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004215 auto buffer_state = Get<BUFFER_STATE>(buffer);
4216 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004217 cb_state->AddChild(buffer_state);
4218 cb_state->AddChild(count_buffer_state);
4219 }
locke-lunargd556cc32019-09-17 01:21:23 -06004220}
4221
4222void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4223 VkDeviceSize offset, VkBuffer countBuffer,
4224 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4225 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004226 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004227 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004228}
4229
4230void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4231 VkDeviceSize offset, VkBuffer countBuffer,
4232 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4233 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004234 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004235 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004236}
4237
4238void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4239 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004240 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004241 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004242}
4243
4244void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4245 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004246 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004247 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004248 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004249 if (!disabled[command_buffer_state] && buffer_state) {
4250 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004251 }
4252}
4253
4254void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4255 VkDeviceSize offset, VkBuffer countBuffer,
4256 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4257 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004258 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004259 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004260 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004261 auto buffer_state = Get<BUFFER_STATE>(buffer);
4262 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004263 if (buffer_state) {
4264 cb_state->AddChild(buffer_state);
4265 }
4266 if (count_buffer_state) {
4267 cb_state->AddChild(count_buffer_state);
4268 }
locke-lunargd556cc32019-09-17 01:21:23 -06004269 }
4270}
4271
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004272void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4273 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4274 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4275 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4276 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4277 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4278 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004279 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004280 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004281 cb_state->hasTraceRaysCmd = true;
4282}
4283
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004284void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4285 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4286 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4287 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4288 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4289 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004290 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004291 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004292 cb_state->hasTraceRaysCmd = true;
4293}
4294
4295void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4296 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4297 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4298 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4299 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4300 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004301 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004302 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004303 cb_state->hasTraceRaysCmd = true;
4304}
4305
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004306std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4307 uint32_t unique_shader_id) const {
4308 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4309 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4310 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4311 : std::make_shared<SHADER_MODULE_STATE>();
4312}
4313
4314std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4315 uint32_t unique_shader_id,
4316 VkShaderModule handle) const {
4317 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4318 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4319 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4320 : std::make_shared<SHADER_MODULE_STATE>();
4321}
4322
locke-lunargd556cc32019-09-17 01:21:23 -06004323void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4324 const VkAllocationCallbacks *pAllocator,
4325 VkShaderModule *pShaderModule, VkResult result,
4326 void *csm_state_data) {
4327 if (VK_SUCCESS != result) return;
4328 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4329
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004330 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004331}
4332
John Zulauf22b0fbe2019-10-15 06:26:16 -06004333void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4334 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4335 VkResult result) {
4336 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004337 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004338
4339 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4340
4341 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004342 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004343 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004344 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004345
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004346 auto format_features = GetImageFormatFeatures(
4347 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4348 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004349
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004350 auto image_state =
4351 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004352 if (!swapchain_image.fake_base_address) {
4353 auto size = image_state->fragment_encoder->TotalSize();
4354 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004355 }
4356
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004357 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004358 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004359 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004360 }
4361 }
4362
4363 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004364 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4365 }
4366}
sourav parmar35e7a002020-06-09 17:58:44 -07004367
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004368void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4369 const VkCopyAccelerationStructureInfoKHR *pInfo,
4370 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004371 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4372 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004373 if (dst_as_state != nullptr && src_as_state != nullptr) {
4374 dst_as_state->built = true;
4375 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4376 }
4377}
4378
sourav parmar35e7a002020-06-09 17:58:44 -07004379void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4380 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004381 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004382 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004383 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004384 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4385 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004386 if (dst_as_state != nullptr && src_as_state != nullptr) {
4387 dst_as_state->built = true;
4388 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004389 if (!disabled[command_buffer_state]) {
4390 cb_state->AddChild(dst_as_state);
4391 cb_state->AddChild(src_as_state);
4392 }
sourav parmar35e7a002020-06-09 17:58:44 -07004393 }
4394 }
4395}
Piers Daniell39842ee2020-07-10 16:42:33 -06004396
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004397void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4398 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4399 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4400 if (cb_state) {
4401 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4402 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4403 if (!disabled[command_buffer_state]) {
4404 cb_state->AddChild(src_as_state);
4405 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004406 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4407 if (dst_buffer) {
4408 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004409 }
4410 }
4411}
4412
4413void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4414 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4415 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4416 if (cb_state) {
4417 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4418 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004419 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4420 if (buffer_state) {
4421 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004422 }
4423 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4424 cb_state->AddChild(dst_as_state);
4425 }
4426 }
4427}
4428
Piers Daniell39842ee2020-07-10 16:42:33 -06004429void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004430 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004431 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004432}
4433
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004434void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4435 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4436 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4437}
4438
Piers Daniell39842ee2020-07-10 16:42:33 -06004439void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004440 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004441 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004442}
4443
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004444void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4445 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4446 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4447}
4448
Piers Daniell39842ee2020-07-10 16:42:33 -06004449void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4450 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004451 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004452 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004453 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004454}
4455
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004456void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4457 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004458 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004459 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4460 cb_state->primitiveTopology = primitiveTopology;
4461}
4462
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004463void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4464 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004465 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4466 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004467 uint32_t bits = (1u << viewportCount) - 1u;
4468 cb_state->viewportWithCountMask |= bits;
4469 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004470 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004471 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004472
4473 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4474 for (size_t i = 0; i < viewportCount; ++i) {
4475 cb_state->dynamicViewports[i] = pViewports[i];
4476 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004477}
4478
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004479void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4480 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004481 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004482}
4483
4484void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004485 const VkViewport *pViewports) {
4486 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004487}
4488
4489void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4490 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004491 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004492 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004493 uint32_t bits = (1u << scissorCount) - 1u;
4494 cb_state->scissorWithCountMask |= bits;
4495 cb_state->trashedScissorMask &= ~bits;
4496 cb_state->scissorWithCountCount = scissorCount;
4497 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004498}
4499
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004500void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4501 const VkRect2D *pScissors) {
4502 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4503}
4504
4505void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4506 const VkRect2D *pScissors) {
4507 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4508}
4509
4510void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4511 uint32_t bindingCount, const VkBuffer *pBuffers,
4512 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4513 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004514 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004515 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004516
4517 uint32_t end = firstBinding + bindingCount;
4518 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4519 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4520 }
4521
4522 for (uint32_t i = 0; i < bindingCount; ++i) {
4523 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004524 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004525 vertex_buffer_binding.offset = pOffsets[i];
4526 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4527 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4528 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004529 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004530 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004531 }
4532 }
4533}
4534
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004535void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4536 uint32_t bindingCount, const VkBuffer *pBuffers,
4537 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4538 const VkDeviceSize *pStrides) {
4539 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4540 CMD_BINDVERTEXBUFFERS2EXT);
4541}
4542
4543void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4544 uint32_t bindingCount, const VkBuffer *pBuffers,
4545 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4546 const VkDeviceSize *pStrides) {
4547 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4548 CMD_BINDVERTEXBUFFERS2);
4549}
4550
Piers Daniell39842ee2020-07-10 16:42:33 -06004551void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004552 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004553 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004554}
4555
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004556void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4557 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4558 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4559}
4560
Piers Daniell39842ee2020-07-10 16:42:33 -06004561void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004562 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004563 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004564}
4565
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004566void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4567 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4568 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4569}
4570
Piers Daniell39842ee2020-07-10 16:42:33 -06004571void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004572 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004573 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004574}
4575
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004576void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4577 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4578 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4579}
4580
Piers Daniell39842ee2020-07-10 16:42:33 -06004581void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4582 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004583 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004584 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004585}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004586
4587void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4588 VkBool32 depthBoundsTestEnable) {
4589 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4590 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4591}
4592
Piers Daniell39842ee2020-07-10 16:42:33 -06004593void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004594 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004595 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004596}
4597
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004598void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4599 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4600 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4601}
4602
Piers Daniell39842ee2020-07-10 16:42:33 -06004603void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4604 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4605 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004606 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004607 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004608}
locke-lunarg4189aa22020-10-21 00:23:48 -06004609
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004610void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4611 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4612 VkCompareOp compareOp) {
4613 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4614 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4615}
4616
locke-lunarg4189aa22020-10-21 00:23:48 -06004617void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4618 uint32_t discardRectangleCount,
4619 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004620 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004621 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004622}
4623
4624void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4625 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004626 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004627 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004628}
4629
4630void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4631 VkCoarseSampleOrderTypeNV sampleOrderType,
4632 uint32_t customSampleOrderCount,
4633 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004634 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004635 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004636}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004637
4638void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004639 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004640 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004641}
4642
4643void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004644 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004645 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004646}
4647
4648void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4649 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004650 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004651 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004652}
4653
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004654void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4655 VkBool32 rasterizerDiscardEnable) {
4656 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4657 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4658}
4659
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004660void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004661 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004662 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004663}
4664
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004665void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4666 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4667 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4668}
4669
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004670void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4671 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004672 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004673 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004674}
Piers Daniell924cd832021-05-18 13:48:47 -06004675
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004676void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4677 VkBool32 primitiveRestartEnable) {
4678 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4679 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4680}
4681
Piers Daniell924cd832021-05-18 13:48:47 -06004682void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4683 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4684 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4685 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004686 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004687 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4688
4689 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4690 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4691 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004692 const auto *dynamic_state = pipeline_state->DynamicState();
4693 if (dynamic_state) {
4694 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4695 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004696 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4697 break;
4698 }
4699 }
4700 }
4701 }
4702 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004703}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004704
ziga-lunarg67b7c392022-03-26 01:45:34 +01004705void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4706 const VkBool32 *pColorWriteEnables) {
4707 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4708 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4709 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4710}
4711
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004712void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004713 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004714 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004715 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004716 // address is used for GPU-AV and ray tracing buffer validation
4717 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004718 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004719 }
4720}
4721
4722void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4723 VkDeviceAddress address) {
4724 RecordGetBufferDeviceAddress(pInfo, address);
4725}
4726
4727void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4728 VkDeviceAddress address) {
4729 RecordGetBufferDeviceAddress(pInfo, address);
4730}
4731
4732void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4733 VkDeviceAddress address) {
4734 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004735}
4736
4737std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4738 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004739 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004740}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004741
4742std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4743 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004744 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004745 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4746}