blob: 4c3eb7ab81f4af91ffc0fa8b00d870c2872cbb23 [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
582void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600583 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
584 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700585 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600586 if (features2) {
587 enabled_features_found = &(features2->features);
588 }
589 }
590
locke-lunargd556cc32019-09-17 01:21:23 -0600591 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600592 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600593 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600594 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600595 }
596
Tony-LunarG273f32f2021-09-28 08:56:30 -0600597 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
598 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600599 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600600 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600601 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600602 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
603 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600604 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600605 }
606
607 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
608 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600609 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
610 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600611 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
612 }
613
614 const auto *pipeline_creation_cache_control_features =
615 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
616 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600617 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600618 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
619 }
620
621 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
622 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600623 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600624 }
625
626 const auto *demote_to_helper_invocation_features =
627 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
628 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600629 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600630 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
631 }
632
633 const auto *terminate_invocation_features =
634 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
635 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600636 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600637 }
638
639 const auto *subgroup_size_control_features =
640 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
641 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600642 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
643 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600644 }
645
646 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
647 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600648 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600649 }
650
651 const auto *texture_compression_astchdr_features =
652 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
653 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600654 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600655 }
656
657 const auto *initialize_workgroup_memory_features =
658 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
659 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600660 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600661 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
662 }
663
664 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
665 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600666 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600667 }
668
669 const auto *shader_integer_dot_product_features =
670 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
671 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600672 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600673 }
674
675 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
676 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600677 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600678 }
679 }
680
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700681 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700682 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600683 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700684 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700685 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600686 enabled_features.core12.drawIndirectCount = VK_FALSE;
687 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
688 enabled_features.core12.descriptorIndexing = VK_FALSE;
689 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
690 enabled_features.core12.shaderOutputLayer = VK_FALSE;
691 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
692 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700693
694 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700695
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700696 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700697 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600698 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
699 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700700 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600701 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700702 }
703
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700704 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700705 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600706 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
707 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700708 }
709
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700710 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700711 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600712 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700713 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600714 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700715 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600716 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700717 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600718 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700719 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600720 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700721 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700723 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700725 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600726 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700727 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600728 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700729 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600730 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700731 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600732 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700733 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700735 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600738 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700739 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600740 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700741 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700743 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700745 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600746 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
747 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700748 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600749 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700750 }
751
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700752 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700753 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700755 }
756
757 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700758 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700761 }
762
763 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700764 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700768 }
769
770 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700771 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700772 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600773 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700774 }
775
776 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700777 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600779 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700780 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700781 }
782
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700783 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700784 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600785 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700786 }
787
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700788 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700789 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600790 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 }
792
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700793 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700794 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600795 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
796 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
797 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700798 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800799
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700800 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800801 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600802 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
803 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800804 }
805
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700806 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800807 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600808 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
809 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
810 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800811 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
812 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700813 }
814
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700815 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700816 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600817 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700818 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700819 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700821 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700822 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600823 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
824 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700825 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600826 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
827 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700828 }
829
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700830 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700831 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600832 enabled_features.core11.multiview = multiview_features->multiview;
833 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
834 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700835 }
836
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700837 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700838 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600839 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
840 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700841 }
842
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700843 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700844 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600845 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700846 }
847
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700848 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600850 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700851 }
852
853 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700854 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600856 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700857 }
858 }
859
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700860 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600861 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600862 physical_device_count = device_group_ci->physicalDeviceCount;
863 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600864 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600865 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600866 }
locke-lunargd556cc32019-09-17 01:21:23 -0600867
sfricke-samsung828e59d2021-08-22 23:20:49 -0700868 // Features from other extensions passesd in create info
869 {
870 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
871 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600872 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700873 }
locke-lunargd556cc32019-09-17 01:21:23 -0600874
sfricke-samsung828e59d2021-08-22 23:20:49 -0700875 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
876 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600877 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700878 }
locke-lunargd556cc32019-09-17 01:21:23 -0600879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
881 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600882 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700883 }
locke-lunargd556cc32019-09-17 01:21:23 -0600884
sfricke-samsung828e59d2021-08-22 23:20:49 -0700885 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
886 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600887 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700888 }
locke-lunargd556cc32019-09-17 01:21:23 -0600889
sfricke-samsung828e59d2021-08-22 23:20:49 -0700890 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
891 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600892 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700893 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700894
sfricke-samsung828e59d2021-08-22 23:20:49 -0700895 const auto *buffer_device_address_ext_features =
896 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
897 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600898 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700899 }
locke-lunargd556cc32019-09-17 01:21:23 -0600900
sfricke-samsung828e59d2021-08-22 23:20:49 -0700901 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
902 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600903 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700904 }
locke-lunargd556cc32019-09-17 01:21:23 -0600905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 const auto *compute_shader_derivatives_features =
907 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
908 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600909 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700910 }
locke-lunargd556cc32019-09-17 01:21:23 -0600911
sfricke-samsung828e59d2021-08-22 23:20:49 -0700912 const auto *fragment_shader_barycentric_features =
913 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
914 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600915 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *shader_image_footprint_features =
919 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
920 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600921 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700922 }
locke-lunargd556cc32019-09-17 01:21:23 -0600923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *fragment_shader_interlock_features =
925 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
926 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600927 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 }
locke-lunargd556cc32019-09-17 01:21:23 -0600929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *texel_buffer_alignment_features =
931 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
932 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600933 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700934 }
locke-lunargd556cc32019-09-17 01:21:23 -0600935
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 const auto *pipeline_exe_props_features =
937 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
938 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600939 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *dedicated_allocation_image_aliasing_features =
943 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
944 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600945 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500947
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
949 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600950 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700951 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100952
sfricke-samsung828e59d2021-08-22 23:20:49 -0700953 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
954 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600955 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700956 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000957
sfricke-samsung828e59d2021-08-22 23:20:49 -0700958 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
959 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600960 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700961 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800962
sfricke-samsung828e59d2021-08-22 23:20:49 -0700963 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
964 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600965 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700967
sfricke-samsung828e59d2021-08-22 23:20:49 -0700968 const auto *ray_tracing_pipeline_features =
969 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
970 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600971 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700973
sfricke-samsung828e59d2021-08-22 23:20:49 -0700974 const auto *ray_tracing_acceleration_structure_features =
975 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
976 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600977 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
981 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600982 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700983 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500984
sfricke-samsung828e59d2021-08-22 23:20:49 -0700985 const auto *fragment_density_map_features =
986 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
987 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600988 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 const auto *fragment_density_map_features2 =
992 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
993 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600994 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700995 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200996
Agarwal, Arpit78509112022-02-17 15:29:05 -0700997 const auto *fragment_density_map_offset_features =
998 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
999 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001000 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001001 }
1002
sfricke-samsung828e59d2021-08-22 23:20:49 -07001003 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1004 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001005 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001006 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001007
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1009 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001010 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001011 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001012
sfricke-samsung828e59d2021-08-22 23:20:49 -07001013 const auto *fragment_shading_rate_features =
1014 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1015 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001016 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001018
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001019 const auto *fragment_shading_rate_enums_features =
1020 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1021 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001022 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001023 }
1024
sfricke-samsung828e59d2021-08-22 23:20:49 -07001025 const auto *extended_dynamic_state_features =
1026 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1027 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001028 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001030
sfricke-samsung828e59d2021-08-22 23:20:49 -07001031 const auto *extended_dynamic_state2_features =
1032 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1033 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001034 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001035 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001036
sfricke-samsung828e59d2021-08-22 23:20:49 -07001037 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1038 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001039 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001040 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001041
sfricke-samsung828e59d2021-08-22 23:20:49 -07001042 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1043 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001044 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001045 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001046
sfricke-samsung828e59d2021-08-22 23:20:49 -07001047 const auto *shader_integer_functions2_features =
1048 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1049 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001050 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001052
sfricke-samsung828e59d2021-08-22 23:20:49 -07001053 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1054 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001055 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001056 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001057
sfricke-samsung828e59d2021-08-22 23:20:49 -07001058 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1059 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001060 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001061 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *shader_image_atomic_int64_features =
1064 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1065 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001066 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001068
sfricke-samsung828e59d2021-08-22 23:20:49 -07001069 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1070 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001071 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001072 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001073
sfricke-samsung828e59d2021-08-22 23:20:49 -07001074 const auto *conditional_rendering_features =
1075 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1076 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001077 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *workgroup_memory_explicit_layout_features =
1081 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1082 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001083 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001084 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001085
sfricke-samsung828e59d2021-08-22 23:20:49 -07001086 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1087 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001088 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001089 }
Locke Linf3873542021-04-26 11:25:10 -06001090
sfricke-samsung828e59d2021-08-22 23:20:49 -07001091 const auto *vertex_input_dynamic_state_features =
1092 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1093 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001094 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001095 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001096
sfricke-samsung828e59d2021-08-22 23:20:49 -07001097 const auto *inherited_viewport_scissor_features =
1098 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1099 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001100 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001102
sfricke-samsung828e59d2021-08-22 23:20:49 -07001103 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1104 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001105 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001106 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001107
sfricke-samsung828e59d2021-08-22 23:20:49 -07001108 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1109 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001110 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001111 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001112
sfricke-samsung828e59d2021-08-22 23:20:49 -07001113 const auto *shader_atomic_float2_features =
1114 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1115 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001116 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001117 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001118
sfricke-samsung828e59d2021-08-22 23:20:49 -07001119 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1120 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001121 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001122 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001123
sfricke-samsung828e59d2021-08-22 23:20:49 -07001124 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1125 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001126 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001128
1129 const auto *ray_tracing_motion_blur_features =
1130 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1131 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001132 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001133 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001134
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001135 const auto *primitive_topology_list_restart_features =
1136 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1137 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001138 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001139 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001140
ziga-lunarge1988962021-09-16 13:32:34 +02001141 const auto *zero_initialize_work_group_memory_features =
1142 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1143 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001144 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001145 }
1146
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001147 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1148 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001149 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001150 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001151
Tony-LunarG69604c42021-11-22 16:00:12 -07001152 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1153 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001154 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001155 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001156
1157 const auto *primitives_generated_query_features =
1158 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1159 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001160 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001161 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001162
1163 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1164 if (image_2d_view_of_3d_features) {
1165 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1166 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001167 }
1168
locke-lunargd556cc32019-09-17 01:21:23 -06001169 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001170 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1171 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001172
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001173 {
1174 uint32_t n_props = 0;
1175 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001176 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001177 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001178 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001179
1180 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001181 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001182 }
1183
1184 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1185 // a path to grab that information from the physical device. This
1186 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1187 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001188 has_format_feature2 =
1189 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1190 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001191 }
1192
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001193 const auto &dev_ext = device_extensions;
1194 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001195
Tony-LunarG273f32f2021-09-28 08:56:30 -06001196 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1197 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001198 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1199 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001200 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001201 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001202 } else {
1203 // VkPhysicalDeviceVulkan11Properties
1204 //
1205 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1206
1207 if (dev_ext.vk_khr_multiview) {
1208 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001209 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1210 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1211 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001212 }
1213
1214 if (dev_ext.vk_khr_maintenance3) {
1215 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001216 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1217 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1218 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001219 }
1220
1221 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001222 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001223 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1224 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1225 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001226 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001227
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001228 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1229 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1230 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1231 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001232
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001233 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001234 }
1235
1236 // VkPhysicalDeviceVulkan12Properties
1237 //
1238 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1239
1240 if (dev_ext.vk_ext_descriptor_indexing) {
1241 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001242 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1243 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001244 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001245 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001246 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001247 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001248 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001249 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001250 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001251 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001252 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001253 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001254 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001255 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1256 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1257 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001258 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001259 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001260 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001261 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001262 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001263 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001264 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001265 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001266 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001267 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001268 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001269 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001270 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001271 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001272 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001273 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001274 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001275 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001276 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001277 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001278 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001279 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001280 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001281 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001282 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001283 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001284 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001285 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001286 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1287 }
1288
1289 if (dev_ext.vk_khr_depth_stencil_resolve) {
1290 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001291 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1292 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1293 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1294 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1295 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001296 }
1297
1298 if (dev_ext.vk_khr_timeline_semaphore) {
1299 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001300 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1301 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001302 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1303 }
1304
1305 if (dev_ext.vk_ext_sampler_filter_minmax) {
1306 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001307 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1308 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001309 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001310 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001311 }
1312
1313 if (dev_ext.vk_khr_shader_float_controls) {
1314 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001315 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1316 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1317 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1318 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001319 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001320 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001321 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001322 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001323 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001324 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1325 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1326 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1327 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1328 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1329 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1330 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1331 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1332 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1333 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1334 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1335 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001336 }
locke-lunargd556cc32019-09-17 01:21:23 -06001337 }
1338
sfricke-samsung828e59d2021-08-22 23:20:49 -07001339 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001340 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1341 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1342 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1343 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1344 &phys_dev_props->inline_uniform_block_props);
1345 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1346 &phys_dev_props->vtx_attrib_divisor_props);
1347 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1348 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1349 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1350 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1351 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1352 &phys_dev_props->texel_buffer_alignment_props);
1353 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1354 &phys_dev_props->fragment_density_map_props);
1355 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1356 &phys_dev_props->fragment_density_map2_props);
1357 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001358 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001359 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1360 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1361 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1362 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1363 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1364 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1365 &phys_dev_props->fragment_shading_rate_props);
1366 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1367 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1368 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1369 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1370 &phys_dev_props->blend_operation_advanced_props);
1371 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1372 &phys_dev_props->conservative_rasterization_props);
1373 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1374 &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001375
sfricke-samsung45996a42021-09-16 13:45:27 -07001376 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001377 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001378 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1379 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001380 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1381 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001382
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001383 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001384 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1385 NULL);
1386 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001387
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001388 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1389 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001390 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001391
locke-lunargd556cc32019-09-17 01:21:23 -06001392 // Store queue family data
1393 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1394 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001395 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001396 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1397 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001398 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001399 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001400 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001401 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1402 VkQueue queue = VK_NULL_HANDLE;
1403 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1404 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1405 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1406 get_info.flags = queue_info.flags;
1407 get_info.queueFamilyIndex = queue_info.queue_family_index;
1408 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001409 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001410 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001411 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001412 }
1413 assert(queue != VK_NULL_HANDLE);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001414 Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001415 }
locke-lunargd556cc32019-09-17 01:21:23 -06001416 }
1417 }
1418}
1419
1420void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1421 if (!device) return;
1422
Jeremy Gebbend177d922021-10-28 13:42:10 -06001423 command_pool_map_.clear();
1424 assert(command_buffer_map_.empty());
1425 pipeline_map_.clear();
1426 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001427
1428 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001429 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001430 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001431 assert(descriptor_set_map_.empty());
1432 desc_template_map_.clear();
1433 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001434 // Because swapchains are associated with Surfaces, which are at instance level,
1435 // they need to be explicitly destroyed here to avoid continued references to
1436 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001437 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001438 entry.second->Destroy();
1439 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001440 swapchain_map_.clear();
1441 image_view_map_.clear();
1442 image_map_.clear();
1443 buffer_view_map_.clear();
1444 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001445 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001446 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001447}
1448
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001449void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1450 VkFence fence, VkResult result) {
1451 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001452 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001453
Jeremy Gebben57642982021-09-14 14:14:55 -06001454 uint64_t early_retire_seq = 0;
1455
1456 if (submitCount == 0) {
1457 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001458 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001459 early_retire_seq = queue_state->Submit(std::move(submission));
1460 }
locke-lunargd556cc32019-09-17 01:21:23 -06001461
1462 // Now process each individual submit
1463 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001464 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001465 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001466 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001467 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001468 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001469 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1470 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1471 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1472 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001473 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001474 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001475
locke-lunargd556cc32019-09-17 01:21:23 -06001476 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001477 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001478 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1479 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1480 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1481 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001482 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001483 }
1484
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001485 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001486 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001487
locke-lunargd556cc32019-09-17 01:21:23 -06001488 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001489 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1490 if (cb_state) {
1491 submission.AddCommandBuffer(std::move(cb_state));
1492 }
locke-lunargd556cc32019-09-17 01:21:23 -06001493 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001494 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001495 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001496 }
1497 auto submit_seq = queue_state->Submit(std::move(submission));
1498 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001499 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001500
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001501 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001502 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001503 }
1504}
1505
Tony-LunarG26fe2842021-11-16 14:07:59 -07001506void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1507 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001508 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001509 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001510 uint64_t early_retire_seq = 0;
1511 if (submitCount == 0) {
1512 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001513 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001514 early_retire_seq = queue_state->Submit(std::move(submission));
1515 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001516
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001517 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1518 CB_SUBMISSION submission;
1519 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001520 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1521 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001522 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001523 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001524 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1525 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001526 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001527 }
1528 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1529 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1530
1531 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001532 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001533 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001534 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001535 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001536 }
1537 auto submit_seq = queue_state->Submit(std::move(submission));
1538 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001539 }
locke-lunargd556cc32019-09-17 01:21:23 -06001540 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001541 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001542 }
1543}
1544
Tony-LunarG26fe2842021-11-16 14:07:59 -07001545void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1546 VkFence fence, VkResult result) {
1547 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1548}
1549
1550void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1551 VkFence fence, VkResult result) {
1552 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1553}
1554
locke-lunargd556cc32019-09-17 01:21:23 -06001555void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1556 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1557 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001558 if (VK_SUCCESS != result) {
1559 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001560 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001561 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1562 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1563 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1564
1565 layer_data::optional<DedicatedBinding> dedicated_binding;
1566
1567 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1568 if (dedicated) {
1569 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001570 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001571 assert(buffer_state);
1572 if (!buffer_state) {
1573 return;
1574 }
1575 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1576 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001577 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001578 assert(image_state);
1579 if (!image_state) {
1580 return;
1581 }
1582 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1583 }
1584 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001585 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1586 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001587 return;
1588}
1589
1590void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001591 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001592 if (mem_info) {
1593 fake_memory.Free(mem_info->fake_base_address);
1594 }
1595 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001596}
1597
1598void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1599 VkFence fence, VkResult result) {
1600 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001601 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001602
Jeremy Gebben57642982021-09-14 14:14:55 -06001603 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001604
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001605 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1606 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001607 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001608 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1609 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1610 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001611 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001612 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001613 if (buffer_state && mem_state) {
1614 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1615 }
locke-lunargd556cc32019-09-17 01:21:23 -06001616 }
1617 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001618 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1619 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1620 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001621 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001622 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001623 if (image_state && mem_state) {
1624 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1625 }
locke-lunargd556cc32019-09-17 01:21:23 -06001626 }
1627 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001628 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1629 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1630 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001631 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1632 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001633 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001634 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001635 if (image_state && mem_state) {
1636 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1637 }
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
1639 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001640 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001641 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001642 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001643 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001644 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001645 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001646 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001647 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001648 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001649 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001650 auto submit_seq = queue_state->Submit(std::move(submission));
1651 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001652 }
1653
1654 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001655 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001656 }
1657}
1658
1659void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1660 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1661 VkResult result) {
1662 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001663 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001664}
1665
Mike Schuchardt2df08912020-12-15 16:28:09 -08001666void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1667 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001668 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1669 if (semaphore_state) {
1670 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001671 }
1672}
1673
Mike Schuchardt2df08912020-12-15 16:28:09 -08001674void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001675 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001676 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001677 if (semaphore_state) {
1678 semaphore_state->RetireTimeline(pSignalInfo->value);
1679 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001680}
1681
locke-lunargd556cc32019-09-17 01:21:23 -06001682void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001683 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001684 if (mem_info) {
1685 mem_info->mapped_range.offset = offset;
1686 mem_info->mapped_range.size = size;
1687 mem_info->p_driver_data = *ppData;
1688 }
1689}
1690
locke-lunargd556cc32019-09-17 01:21:23 -06001691void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1692 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1693 if (VK_SUCCESS != result) return;
1694
1695 // When we know that all fences are complete we can clean/remove their CBs
1696 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1697 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001698 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001699 if (fence_state) {
1700 fence_state->Retire();
1701 }
locke-lunargd556cc32019-09-17 01:21:23 -06001702 }
1703 }
1704 // NOTE : Alternate case not handled here is when some fences have completed. In
1705 // this case for app to guarantee which fences completed it will have to call
1706 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1707}
1708
John Zulauff89de662020-04-13 18:57:34 -06001709void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1710 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001711 if (VK_SUCCESS != result) return;
1712
Jeremy Gebben15332642021-12-15 19:33:15 -07001713 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1714 // the application calls vkGetSemaphoreCounterValue() on each of them.
1715 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1716 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1717 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1718 if (semaphore_state) {
1719 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1720 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001721 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001722 }
1723}
1724
John Zulauff89de662020-04-13 18:57:34 -06001725void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1726 VkResult result) {
1727 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1728}
1729
1730void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1731 uint64_t timeout, VkResult result) {
1732 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1733}
1734
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001735void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1736 VkResult result) {
1737 if (VK_SUCCESS != result) return;
1738
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001739 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001740 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001741 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001742 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001743}
1744
1745void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1746 VkResult result) {
1747 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1748}
1749void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1750 VkResult result) {
1751 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1752}
1753
locke-lunargd556cc32019-09-17 01:21:23 -06001754void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1755 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001756 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001757 if (fence_state) {
1758 fence_state->Retire();
1759 }
locke-lunargd556cc32019-09-17 01:21:23 -06001760}
1761
Yilong Lice03a312022-01-02 02:08:35 -08001762void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1763 if (Get<QUEUE_STATE>(queue) == nullptr) {
1764 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1765 }
1766}
1767
1768void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1769 VkQueue *pQueue) {
1770 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1771}
1772
1773void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1774 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1775}
1776
locke-lunargd556cc32019-09-17 01:21:23 -06001777void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1778 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001779 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001780 if (queue_state) {
1781 queue_state->Retire();
1782 }
locke-lunargd556cc32019-09-17 01:21:23 -06001783}
1784
1785void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1786 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001787 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001788 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001789 }
1790}
1791
1792void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001793 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001794}
1795
1796void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1797 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001798 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001799}
1800
1801void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001802 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001803}
1804
1805void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1806 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001807 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001808}
1809
locke-lunargd556cc32019-09-17 01:21:23 -06001810void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001811 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001812 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001813 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001814 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001815 if (mem_state) {
1816 buffer_state->SetMemBinding(mem_state, memoryOffset);
1817 }
locke-lunargd556cc32019-09-17 01:21:23 -06001818 }
1819}
1820
1821void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1822 VkDeviceSize memoryOffset, VkResult result) {
1823 if (VK_SUCCESS != result) return;
1824 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1825}
1826
1827void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001828 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001829 for (uint32_t i = 0; i < bindInfoCount; i++) {
1830 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1831 }
1832}
1833
1834void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001835 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001836 for (uint32_t i = 0; i < bindInfoCount; i++) {
1837 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1838 }
1839}
1840
Spencer Fricke6c127102020-04-16 06:25:20 -07001841void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001842 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001843 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001844 buffer_state->memory_requirements_checked = true;
1845 }
1846}
1847
1848void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1849 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001850 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001851}
1852
1853void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001854 const VkBufferMemoryRequirementsInfo2 *pInfo,
1855 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001856 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001857}
1858
1859void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001860 const VkBufferMemoryRequirementsInfo2 *pInfo,
1861 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001862 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001863}
1864
Spencer Fricke6c127102020-04-16 06:25:20 -07001865void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001866 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001867 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001868 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001869 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001870 if (plane_info != nullptr) {
1871 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001872 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001873 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001874 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001875 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001876 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001877 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001878 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001879 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001880 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001881 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001882 }
locke-lunargd556cc32019-09-17 01:21:23 -06001883 }
1884}
1885
1886void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1887 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001888 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001889}
1890
1891void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1892 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001893 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001894}
1895
1896void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1897 const VkImageMemoryRequirementsInfo2 *pInfo,
1898 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001899 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001900}
1901
locke-lunargd556cc32019-09-17 01:21:23 -06001902void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1903 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1904 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001905 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001906 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001907}
1908
1909void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001910 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1911 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001912 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001913 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001914}
1915
1916void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001917 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1918 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001919 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001920 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001921}
1922
1923void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1924 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001925 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001926}
1927
1928void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1929 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001930 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001931}
1932
1933void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1934 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001935 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001936}
1937
1938void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1939 const VkAllocationCallbacks *pAllocator) {
1940 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001941 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001942 // Any bound cmd buffers are now invalid
1943 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001944 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1945 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1946 custom_border_color_sampler_count--;
1947 }
locke-lunargd556cc32019-09-17 01:21:23 -06001948 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001949 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001950}
1951
1952void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1953 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001954 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001955}
1956
1957void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1958 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001959 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001960}
1961
locke-lunargd556cc32019-09-17 01:21:23 -06001962void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1963 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001964 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1965 if (pool) {
1966 pool->Free(commandBufferCount, pCommandBuffers);
1967 }
locke-lunargd556cc32019-09-17 01:21:23 -06001968}
1969
1970void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1971 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1972 VkResult result) {
1973 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001974 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001975 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001976}
1977
1978void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1979 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1980 VkResult result) {
1981 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001982
1983 uint32_t index_count = 0, n_perf_pass = 0;
1984 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001985 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001986 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001987 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001988
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001989 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001990 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1991 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1992 switch (counter.scope) {
1993 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001994 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001995 break;
1996 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001997 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001998 break;
1999 default:
2000 break;
2001 }
2002 }
2003
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002004 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002005 }
2006
Jeremy Gebben082a9832021-10-28 13:40:11 -06002007 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 -06002008
locke-lunargd556cc32019-09-17 01:21:23 -06002009}
2010
2011void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2012 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002013 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002014}
2015
2016void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2017 VkCommandPoolResetFlags flags, VkResult result) {
2018 if (VK_SUCCESS != result) return;
2019 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002020 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2021 if (pool) {
2022 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002023 }
2024}
2025
2026void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2027 VkResult result) {
2028 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002029 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002030 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002031 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002032 }
2033 }
2034}
2035
locke-lunargd556cc32019-09-17 01:21:23 -06002036void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2037 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2042 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002043 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002044}
2045
2046void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2047 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2048 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002049 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002050}
2051
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002052std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2053 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2054 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2055 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2056}
2057
locke-lunargd556cc32019-09-17 01:21:23 -06002058bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2059 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2060 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002061 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002062 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002063 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2064 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2065 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2066 cgpl_state->pipe_state.reserve(count);
2067 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002068 const auto &create_info = pCreateInfos[i];
2069 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2070 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2071
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002072 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002073 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002074 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002075 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2076 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002077 } else {
2078 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2079 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2080 if (!is_graphics_lib && !has_link_info) {
2081 skip = true;
2082 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002083 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002084 cgpl_state->pipe_state.push_back(
2085 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002086 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002087 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002088}
2089
2090void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2091 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2092 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2093 VkResult result, void *cgpl_state_data) {
2094 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2095 // This API may create pipelines regardless of the return value
2096 for (uint32_t i = 0; i < count; i++) {
2097 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002098 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002099 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002100 }
2101 }
2102 cgpl_state->pipe_state.clear();
2103}
2104
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002105std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2106 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2107 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2108}
2109
locke-lunargd556cc32019-09-17 01:21:23 -06002110bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2111 const VkComputePipelineCreateInfo *pCreateInfos,
2112 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002113 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002114 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2115 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2116 ccpl_state->pipe_state.reserve(count);
2117 for (uint32_t i = 0; i < count; i++) {
2118 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002119 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002120 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002121 }
2122 return false;
2123}
2124
2125void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2126 const VkComputePipelineCreateInfo *pCreateInfos,
2127 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2128 VkResult result, void *ccpl_state_data) {
2129 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2130
2131 // This API may create pipelines regardless of the return value
2132 for (uint32_t i = 0; i < count; i++) {
2133 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002134 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002135 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002136 }
2137 }
2138 ccpl_state->pipe_state.clear();
2139}
2140
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002141std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2142 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2143 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2144}
2145
locke-lunargd556cc32019-09-17 01:21:23 -06002146bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2147 uint32_t count,
2148 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2149 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002150 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002151 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2152 crtpl_state->pipe_state.reserve(count);
2153 for (uint32_t i = 0; i < count; i++) {
2154 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002155 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002156 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002157 }
2158 return false;
2159}
2160
2161void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2162 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2163 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2164 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2165 // This API may create pipelines regardless of the return value
2166 for (uint32_t i = 0; i < count; i++) {
2167 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002168 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002169 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002170 }
2171 }
2172 crtpl_state->pipe_state.clear();
2173}
2174
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002175std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2176 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2177 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2178}
2179
sourav parmarcd5fb182020-07-17 12:58:44 -07002180bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2181 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002182 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2183 const VkAllocationCallbacks *pAllocator,
2184 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002185 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002186 crtpl_state->pipe_state.reserve(count);
2187 for (uint32_t i = 0; i < count; i++) {
2188 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002189 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002190 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002191 }
2192 return false;
2193}
2194
sourav parmarcd5fb182020-07-17 12:58:44 -07002195void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2196 VkPipelineCache pipelineCache, uint32_t count,
2197 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2198 const VkAllocationCallbacks *pAllocator,
2199 VkPipeline *pPipelines, VkResult result,
2200 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002201 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002202 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002203 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002204
2205 if (!operation_is_deferred) {
2206 for (uint32_t i = 0; i < count; i++) {
2207 if (pPipelines[i] != VK_NULL_HANDLE) {
2208 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2209 Add(std::move((crtpl_state->pipe_state)[i]));
2210 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002211 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002212 } else {
2213 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2214 if (wrap_handles) {
2215 deferredOperation = layer_data->Unwrap(deferredOperation);
2216 }
2217 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2218 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2219 if (find_res->first) {
2220 cleanup_fn = std::move(find_res->second);
2221 }
2222 auto &pipeline_states = crtpl_state->pipe_state;
2223 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2224 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2225 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2226 pipeline_states[i]->SetHandle(pipelines[i]);
2227 this->Add(std::move(pipeline_states[i]));
2228 }
2229 });
2230 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002231 }
2232 crtpl_state->pipe_state.clear();
2233}
2234
locke-lunargd556cc32019-09-17 01:21:23 -06002235void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2236 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2237 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002238 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002239 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2240 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002241 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002242 }
locke-lunargd556cc32019-09-17 01:21:23 -06002243}
2244
2245void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2246 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2247 const VkAllocationCallbacks *pAllocator,
2248 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2249 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002250 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002251}
2252
locke-lunargd556cc32019-09-17 01:21:23 -06002253void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2254 const VkAllocationCallbacks *pAllocator,
2255 VkPipelineLayout *pPipelineLayout, VkResult result) {
2256 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002257 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002258}
2259
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002260std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2261 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2262 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2263}
2264
locke-lunargd556cc32019-09-17 01:21:23 -06002265void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2266 const VkAllocationCallbacks *pAllocator,
2267 VkDescriptorPool *pDescriptorPool, VkResult result) {
2268 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002269 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002270}
2271
2272void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2273 VkDescriptorPoolResetFlags flags, VkResult result) {
2274 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002275 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2276 if (pool) {
2277 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002278 }
locke-lunargd556cc32019-09-17 01:21:23 -06002279}
2280
2281bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2282 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002283 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002284 // Always update common data
2285 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2286 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2287 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2288
2289 return false;
2290}
2291
2292// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2293void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2294 VkDescriptorSet *pDescriptorSets, VkResult result,
2295 void *ads_state_data) {
2296 if (VK_SUCCESS != result) return;
2297 // All the updates are contained in a single cvdescriptorset function
2298 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2299 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002300 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2301 if (pool_state) {
2302 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2303 }
locke-lunargd556cc32019-09-17 01:21:23 -06002304}
2305
2306void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2307 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002308 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2309 if (pool_state) {
2310 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002311 }
2312}
2313
2314void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2315 const VkWriteDescriptorSet *pDescriptorWrites,
2316 uint32_t descriptorCopyCount,
2317 const VkCopyDescriptorSet *pDescriptorCopies) {
2318 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2319 pDescriptorCopies);
2320}
2321
2322void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002323 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002324 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002325 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002326 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002327 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002328 }
2329}
2330
locke-lunargd556cc32019-09-17 01:21:23 -06002331void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2332 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002333 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002334 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002335
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002336 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002337}
2338
2339void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002340 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002341 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002342
2343 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002344}
2345
2346void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2347 VkResult result) {
2348 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002349 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2350 if (cb_state) {
2351 cb_state->Reset();
2352 }
locke-lunargd556cc32019-09-17 01:21:23 -06002353 }
2354}
2355
2356CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2357 // initially assume everything is static state
2358 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2359
2360 if (ds) {
2361 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002362 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002363 }
2364 }
locke-lunargd556cc32019-09-17 01:21:23 -06002365 return flags;
2366}
2367
2368// Validation cache:
2369// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002370
2371void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2372 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002373 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002374 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002375 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002376
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002377 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002378 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002379 const auto *raster_state = pipe_state->RasterizationState();
2380 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002381 const auto *viewport_state = pipe_state->ViewportState();
2382 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002383 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002384 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002385 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002386 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002387
2388 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002389 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2390 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002391 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002392 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002393 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002394 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002395 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002396 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002397
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002398 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002399 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2400 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2401 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002402 if (!has_dynamic_viewport_count) {
2403 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002404 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002405 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2406 // should become = ~uint32_t(0) if the other interpretation is correct.
2407 }
2408 }
2409 if (!has_dynamic_scissor_count) {
2410 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002411 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002412 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2413 // should become = ~uint32_t(0) if the other interpretation is correct.
2414 }
2415 }
locke-lunargd556cc32019-09-17 01:21:23 -06002416 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002417 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002418 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002419 if (!disabled[command_buffer_state]) {
2420 cb_state->AddChild(pipe_state);
2421 }
locke-lunargd556cc32019-09-17 01:21:23 -06002422}
2423
2424void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2425 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002426 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002427 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002428 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2429 cb_state->viewportMask |= bits;
2430 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002431
2432 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2433 for (size_t i = 0; i < viewportCount; ++i) {
2434 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2435 }
locke-lunargd556cc32019-09-17 01:21:23 -06002436}
2437
2438void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2439 uint32_t exclusiveScissorCount,
2440 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002441 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002442 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002443 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2444 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002445}
2446
2447void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2448 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002449 if (disabled[command_buffer_state]) return;
2450
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002451 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002452 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002453
2454 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002455 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002456 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002457 }
2458}
2459
2460void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2461 uint32_t viewportCount,
2462 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002463 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002464 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002465 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2466 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002467}
2468
2469void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2470 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2471 const VkAllocationCallbacks *pAllocator,
2472 VkAccelerationStructureNV *pAccelerationStructure,
2473 VkResult result) {
2474 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002475 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002476}
2477
Jeff Bolz95176d02020-04-01 00:36:16 -05002478void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2479 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2480 const VkAllocationCallbacks *pAllocator,
2481 VkAccelerationStructureKHR *pAccelerationStructure,
2482 VkResult result) {
2483 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002484 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2485 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002486}
2487
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002488void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2489 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2490 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2491 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2492 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002493 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002494 if (dst_as_state != nullptr) {
2495 dst_as_state->Build(&pInfos[i]);
2496 }
2497 }
2498}
2499
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002500// helper method for device side acceleration structure builds
2501void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2502 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2503 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2504 if (dst_as_state) {
2505 dst_as_state->Build(&info);
2506 }
2507 if (disabled[command_buffer_state]) {
2508 return;
2509 }
2510 if (dst_as_state) {
2511 cb_state.AddChild(dst_as_state);
2512 }
2513 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2514 if (src_as_state) {
2515 cb_state.AddChild(src_as_state);
2516 }
2517 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2518 if (scratch_buffer) {
2519 cb_state.AddChild(scratch_buffer);
2520 }
2521
2522 for (uint32_t i = 0; i < info.geometryCount; i++) {
2523 // only one of pGeometries and ppGeometries can be non-null
2524 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2525 switch (geom.geometryType) {
2526 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2527 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2528 if (vertex_buffer) {
2529 cb_state.AddChild(vertex_buffer);
2530 }
2531 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2532 if (index_buffer) {
2533 cb_state.AddChild(index_buffer);
2534 }
2535 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2536 if (transform_buffer) {
2537 cb_state.AddChild(transform_buffer);
2538 }
2539 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2540 if (motion_data) {
2541 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2542 if (motion_buffer) {
2543 cb_state.AddChild(motion_buffer);
2544 }
2545 }
2546 } break;
2547 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2548 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2549 if (data_buffer) {
2550 cb_state.AddChild(data_buffer);
2551 }
2552 } break;
2553 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2554 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2555 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2556 // easily ensure that's true.
2557 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2558 if (data_buffer) {
2559 cb_state.AddChild(data_buffer);
2560 }
2561 } break;
2562 default:
2563 break;
2564 }
2565 }
2566}
2567
sourav parmarcd5fb182020-07-17 12:58:44 -07002568void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2569 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2570 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002571 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002572 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002573 return;
2574 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002575 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002576 for (uint32_t i = 0; i < infoCount; i++) {
2577 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002578 }
2579 cb_state->hasBuildAccelerationStructureCmd = true;
2580}
2581
2582void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2583 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2584 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2585 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002586 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2587 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002588 return;
2589 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002590 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002591 for (uint32_t i = 0; i < infoCount; i++) {
2592 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002593 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002594 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2595 if (indirect_buffer) {
2596 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002597 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002598 }
2599 }
2600 cb_state->hasBuildAccelerationStructureCmd = true;
2601}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002602
locke-lunargd556cc32019-09-17 01:21:23 -06002603void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002604 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002605 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002606 if (as_state != nullptr) {
2607 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002608 as_state->memory_requirements_checked = true;
2609 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002610 as_state->build_scratch_memory_requirements_checked = true;
2611 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002612 as_state->update_scratch_memory_requirements_checked = true;
2613 }
2614 }
2615}
2616
sourav parmarcd5fb182020-07-17 12:58:44 -07002617void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2618 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002619 if (VK_SUCCESS != result) return;
2620 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002621 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002622
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002623 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002624 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002625 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002626 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002627 if (mem_state) {
2628 as_state->SetMemBinding(mem_state, info.memoryOffset);
2629 }
locke-lunargd556cc32019-09-17 01:21:23 -06002630
2631 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002632 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002633 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002634 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2635 }
2636 }
2637 }
2638}
2639
2640void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2641 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2642 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002643 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2644 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002645 return;
2646 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002647 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002648
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002649 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002650 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002651 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002652 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002653 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002654 }
locke-lunargd556cc32019-09-17 01:21:23 -06002655 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002656 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002657 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002658 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002659 cb_state->AddChild(src_as_state);
2660 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002661 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2662 if (instance_buffer) {
2663 cb_state->AddChild(instance_buffer);
2664 }
2665 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2666 if (scratch_buffer) {
2667 cb_state->AddChild(scratch_buffer);
2668 }
2669
2670 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2671 const auto& geom = pInfo->pGeometries[i];
2672
2673 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2674 if (vertex_buffer) {
2675 cb_state->AddChild(vertex_buffer);
2676 }
2677 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2678 if (index_buffer) {
2679 cb_state->AddChild(index_buffer);
2680 }
2681 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2682 if (transform_buffer) {
2683 cb_state->AddChild(transform_buffer);
2684 }
2685
2686 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2687 if (aabb_buffer) {
2688 cb_state->AddChild(aabb_buffer);
2689 }
2690 }
2691
locke-lunargd556cc32019-09-17 01:21:23 -06002692 }
2693 cb_state->hasBuildAccelerationStructureCmd = true;
2694}
2695
2696void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2697 VkAccelerationStructureNV dst,
2698 VkAccelerationStructureNV src,
2699 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002700 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002701 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002702 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2703 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002704 if (!disabled[command_buffer_state]) {
2705 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2706 }
locke-lunargd556cc32019-09-17 01:21:23 -06002707 if (dst_as_state != nullptr && src_as_state != nullptr) {
2708 dst_as_state->built = true;
2709 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002710 }
2711 }
2712}
2713
Jeff Bolz95176d02020-04-01 00:36:16 -05002714void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2715 VkAccelerationStructureKHR accelerationStructure,
2716 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002717 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002718}
2719
Jeff Bolz95176d02020-04-01 00:36:16 -05002720void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2721 VkAccelerationStructureNV accelerationStructure,
2722 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002723 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002724}
2725
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002726void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2727 uint32_t viewportCount,
2728 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002729 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002730 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002731}
2732
locke-lunargd556cc32019-09-17 01:21:23 -06002733void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002734 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002735 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002736}
2737
2738void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2739 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002740 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002741 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002742}
2743
2744void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2745 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002746 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002747 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002748}
2749
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002750void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2751 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002752 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002753 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002754 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2755 cb_state->scissorMask |= bits;
2756 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002757}
2758
locke-lunargd556cc32019-09-17 01:21:23 -06002759void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002760 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002761 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002762}
2763
2764void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2765 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002766 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002767 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002768}
2769
2770void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2771 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002772 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002773 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002774}
2775
2776void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2777 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002778 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002779 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002780}
2781
2782void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2783 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002784 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002785 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002786}
2787
locke-lunargd556cc32019-09-17 01:21:23 -06002788// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2789void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2790 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2791 uint32_t firstSet, uint32_t setCount,
2792 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2793 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002794 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002795 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002796 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002797 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002798
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002799 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2800 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002801}
2802
locke-lunargd556cc32019-09-17 01:21:23 -06002803void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2804 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2805 uint32_t set, uint32_t descriptorWriteCount,
2806 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002807 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002808 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002809 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002810}
2811
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002812void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2813 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2814 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002815 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2816 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002817 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002818 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2819 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002820
2821 auto &push_constant_data = cb_state->push_constant_data;
2822 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2823 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002824 cb_state->push_constant_pipeline_layout_set = layout;
2825
2826 auto flags = stageFlags;
2827 uint32_t bit_shift = 0;
2828 while (flags) {
2829 if (flags & 1) {
2830 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2831 const auto it = cb_state->push_constant_data_update.find(flag);
2832
2833 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002834 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002835 }
2836 }
2837 flags = flags >> 1;
2838 ++bit_shift;
2839 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002840 }
2841}
2842
locke-lunargd556cc32019-09-17 01:21:23 -06002843void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2844 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002845 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002846
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002847 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002848 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002849 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002850 cb_state->index_buffer_binding.offset = offset;
2851 cb_state->index_buffer_binding.index_type = indexType;
2852 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002853 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002854 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002855 }
locke-lunargd556cc32019-09-17 01:21:23 -06002856}
2857
2858void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2859 uint32_t bindingCount, const VkBuffer *pBuffers,
2860 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002861 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002862 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002863
2864 uint32_t end = firstBinding + bindingCount;
2865 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2866 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2867 }
2868
2869 for (uint32_t i = 0; i < bindingCount; ++i) {
2870 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002871 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002872 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002873 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2874 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002875 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002876 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002877 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002878 }
locke-lunargd556cc32019-09-17 01:21:23 -06002879 }
2880}
2881
2882void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2883 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002884 if (disabled[command_buffer_state]) return;
2885
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002886 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002887 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002888}
2889
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002890void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2891 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002892 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002893 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002894}
2895
2896void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2897 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002898 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002899 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2900
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002901 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2902 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002903}
2904
Tony-LunarGc43525f2021-11-15 16:12:38 -07002905void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2906 const VkDependencyInfo* pDependencyInfo) {
2907 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2908 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2909
2910 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2911 cb_state->RecordBarriers(*pDependencyInfo);
2912}
2913
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002914void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2915 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002916 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002917 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002918}
2919
2920void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2921 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002922 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002923 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002924}
2925
Tony-LunarGa2662db2021-11-16 07:26:24 -07002926void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2927 VkPipelineStageFlags2 stageMask) {
2928 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2929 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2930}
2931
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002932void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2933 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2934 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2935 uint32_t bufferMemoryBarrierCount,
2936 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2937 uint32_t imageMemoryBarrierCount,
2938 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002939 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2940 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002941 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2942 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002943}
2944
2945void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2946 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002947 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002948 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002949 const auto &dep_info = pDependencyInfos[i];
2950 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2951 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2952 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002953 }
2954}
2955
Tony-LunarG1364cf52021-11-17 16:10:11 -07002956void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2957 const VkDependencyInfo *pDependencyInfos) {
2958 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2959 for (uint32_t i = 0; i < eventCount; i++) {
2960 const auto &dep_info = pDependencyInfos[i];
2961 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2962 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2963 cb_state->RecordBarriers(dep_info);
2964 }
2965}
2966
Jeremy Gebben79649152021-06-22 14:46:24 -06002967void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2968 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2969 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2970 uint32_t bufferMemoryBarrierCount,
2971 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2972 uint32_t imageMemoryBarrierCount,
2973 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002974 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002975 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2976 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2977 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002978}
2979
2980void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2981 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002982 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002983 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2984 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002985}
2986
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002987void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2988 const VkDependencyInfo *pDependencyInfo) {
2989 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2990 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2991 cb_state->RecordBarriers(*pDependencyInfo);
2992}
2993
locke-lunargd556cc32019-09-17 01:21:23 -06002994void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2995 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002996 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002997
locke-lunargd556cc32019-09-17 01:21:23 -06002998 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002999 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003000 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003001 if (!disabled[query_validation]) {
3002 cb_state->BeginQuery(query);
3003 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003004 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003005 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003006 cb_state->AddChild(pool_state);
3007 }
locke-lunargd556cc32019-09-17 01:21:23 -06003008}
3009
3010void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003011 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003012 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003013 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003014 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003015 if (!disabled[query_validation]) {
3016 cb_state->EndQuery(query_obj);
3017 }
3018 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003019 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003020 cb_state->AddChild(pool_state);
3021 }
locke-lunargd556cc32019-09-17 01:21:23 -06003022}
3023
3024void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3025 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003026 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003027 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003028
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003029 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003030 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003031
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003032 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003033 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003034 cb_state->AddChild(pool_state);
3035 }
locke-lunargd556cc32019-09-17 01:21:23 -06003036}
3037
3038void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3039 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3040 VkDeviceSize dstOffset, VkDeviceSize stride,
3041 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003042 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3043
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003044 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003045 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003046 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003047 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003048 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003049 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003050}
3051
3052void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3053 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003054 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003055 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003056}
3057
3058void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3059 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3060 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003061 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003062 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003063}
3064
Tony-LunarGde9936b2021-11-17 15:34:11 -07003065void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3066 VkQueryPool queryPool, uint32_t slot) {
3067 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3068 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3069}
3070
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003071void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3072 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3073 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3074 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003075 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003076 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003077 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003078 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003079 cb_state->AddChild(pool_state);
3080 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003081 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003082}
3083
locke-lunargd556cc32019-09-17 01:21:23 -06003084void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3085 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3086 VkResult result) {
3087 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003088
Jeremy Gebben88f58142021-06-01 10:07:52 -06003089 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003090 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003091 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003092
locke-lunargd556cc32019-09-17 01:21:23 -06003093 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003094 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003095 }
3096 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003097
Jeremy Gebben9f537102021-10-05 16:37:12 -06003098 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003099 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003100}
3101
locke-lunargd556cc32019-09-17 01:21:23 -06003102void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3103 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3104 VkResult result) {
3105 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003106 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003107}
3108
Mike Schuchardt2df08912020-12-15 16:28:09 -08003109void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003110 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3111 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003112 if (VK_SUCCESS != result) return;
3113
Jeremy Gebben082a9832021-10-28 13:40:11 -06003114 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003115}
3116
Mike Schuchardt2df08912020-12-15 16:28:09 -08003117void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003118 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3119 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003120 if (VK_SUCCESS != result) return;
3121
Jeremy Gebben082a9832021-10-28 13:40:11 -06003122 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003123}
3124
locke-lunargd556cc32019-09-17 01:21:23 -06003125void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3126 const VkRenderPassBeginInfo *pRenderPassBegin,
3127 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003128 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003129 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003130}
3131
3132void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3133 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003134 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003135 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003136 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003137}
3138
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003139void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3140 uint32_t counterBufferCount,
3141 const VkBuffer *pCounterBuffers,
3142 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003143 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003144
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003145 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003146 cb_state->transform_feedback_active = true;
3147}
3148
3149void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3150 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3151 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003152 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003153
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003154 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003155 cb_state->transform_feedback_active = false;
3156}
3157
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003158void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3159 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003160 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003161
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003162 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003163 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003164 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3165 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003166}
3167
3168void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003169 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003170
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003171 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003172 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003173 cb_state->conditional_rendering_inside_render_pass = false;
3174 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003175}
3176
amhagana448ea52021-11-02 14:09:14 -04003177void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003178 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003179 cb_state->activeRenderPass = nullptr;
3180}
3181
3182void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3183 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003184 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003185 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3186}
3187
Tony-LunarG40b33882021-12-02 12:40:11 -07003188void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3189 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3190 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3191}
3192
amhagana448ea52021-11-02 14:09:14 -04003193void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3194 RecordCmdEndRenderingRenderPassState(commandBuffer);
3195}
3196
Tony-LunarG40b33882021-12-02 12:40:11 -07003197void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3198 RecordCmdEndRenderingRenderPassState(commandBuffer);
3199}
3200
Tony-LunarG977448c2019-12-02 14:52:02 -07003201void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3202 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003203 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003204 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003205 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003206}
3207
locke-lunargd556cc32019-09-17 01:21:23 -06003208void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003209 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003210 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003211}
3212
3213void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003214 const VkSubpassBeginInfo *pSubpassBeginInfo,
3215 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003216 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003217 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003218}
3219
Tony-LunarG977448c2019-12-02 14:52:02 -07003220void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003221 const VkSubpassBeginInfo *pSubpassBeginInfo,
3222 const VkSubpassEndInfo *pSubpassEndInfo) {
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->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003225}
3226
3227void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
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->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003230}
3231
3232void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003233 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003234 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003235 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003236}
3237
Tony-LunarG977448c2019-12-02 14:52:02 -07003238void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003239 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003240 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003241 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003242}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003243
locke-lunargd556cc32019-09-17 01:21:23 -06003244void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3245 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003246 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003247
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003248 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003249}
3250
3251void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3252 VkFlags flags, void **ppData, VkResult result) {
3253 if (VK_SUCCESS != result) return;
3254 RecordMappedMemory(mem, offset, size, ppData);
3255}
3256
3257void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003258 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003259 if (mem_info) {
3260 mem_info->mapped_range = MemRange();
3261 mem_info->p_driver_data = nullptr;
3262 }
3263}
3264
3265void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003266 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003267 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003268 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3269 // See: VUID-vkGetImageSubresourceLayout-image-01895
3270 image_state->fragment_encoder =
3271 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003272 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003273 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003274 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003275 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003276 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003277
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003278 if (!swapchain_image.fake_base_address) {
3279 auto size = image_state->fragment_encoder->TotalSize();
3280 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003281 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003282 // All images bound to this swapchain and index are aliases
3283 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003284 }
3285 } else {
3286 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003287 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003288 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003289 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003290 }
locke-lunargd556cc32019-09-17 01:21:23 -06003291 }
locke-lunargd556cc32019-09-17 01:21:23 -06003292 }
3293}
3294
3295void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3296 VkDeviceSize memoryOffset, VkResult result) {
3297 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003298 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003299 bind_info.image = image;
3300 bind_info.memory = mem;
3301 bind_info.memoryOffset = memoryOffset;
3302 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003303}
3304
3305void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003306 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003307 if (VK_SUCCESS != result) return;
3308 for (uint32_t i = 0; i < bindInfoCount; i++) {
3309 UpdateBindImageMemoryState(pBindInfos[i]);
3310 }
3311}
3312
3313void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003314 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003315 if (VK_SUCCESS != result) return;
3316 for (uint32_t i = 0; i < bindInfoCount; i++) {
3317 UpdateBindImageMemoryState(pBindInfos[i]);
3318 }
3319}
3320
3321void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003322 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003323 if (event_state) {
3324 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3325 }
locke-lunargd556cc32019-09-17 01:21:23 -06003326}
3327
3328void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3329 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3330 VkResult result) {
3331 if (VK_SUCCESS != result) return;
3332 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3333 pImportSemaphoreFdInfo->flags);
3334}
3335
3336void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003337 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003338 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003339 if (semaphore_state) {
3340 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003341 }
3342}
3343
3344#ifdef VK_USE_PLATFORM_WIN32_KHR
3345void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3346 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3347 if (VK_SUCCESS != result) return;
3348 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3349 pImportSemaphoreWin32HandleInfo->flags);
3350}
3351
3352void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3353 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3354 HANDLE *pHandle, VkResult result) {
3355 if (VK_SUCCESS != result) return;
3356 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3357}
3358
3359void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3360 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3361 if (VK_SUCCESS != result) return;
3362 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3363 pImportFenceWin32HandleInfo->flags);
3364}
3365
3366void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3367 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3368 HANDLE *pHandle, VkResult result) {
3369 if (VK_SUCCESS != result) return;
3370 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3371}
3372#endif
3373
3374void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3375 VkResult result) {
3376 if (VK_SUCCESS != result) return;
3377 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3378}
3379
Mike Schuchardt2df08912020-12-15 16:28:09 -08003380void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3381 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003382 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003383
3384 if (fence_node) {
3385 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003386 }
3387}
3388
3389void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3390 VkResult result) {
3391 if (VK_SUCCESS != result) return;
3392 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3393}
3394
Mike Schuchardt2df08912020-12-15 16:28:09 -08003395void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003396 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003397 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003398 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003399 }
3400}
3401
3402void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3403 VkResult result) {
3404 if (VK_SUCCESS != result) return;
3405 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3406}
3407
3408void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3409 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3410 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003411 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003412}
3413
3414void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003415 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003416 SWAPCHAIN_NODE *old_swapchain_state) {
3417 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003418 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003419 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003420 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003421 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3422 surface_state->AddParent(swapchain.get());
3423 surface_state->swapchain = swapchain.get();
3424 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003425 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003426 } else {
3427 surface_state->swapchain = nullptr;
3428 }
3429 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003430 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003431 if (old_swapchain_state) {
3432 old_swapchain_state->retired = true;
3433 }
3434 return;
3435}
3436
3437void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3438 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3439 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003440 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003441 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003442 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003443}
3444
3445void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3446 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003447 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003448}
3449
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003450void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3451 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3452 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3453 VkResult result) {
3454 if (VK_SUCCESS != result) return;
3455 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003456 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003457}
3458
locke-lunargd556cc32019-09-17 01:21:23 -06003459void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003460 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003461 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003462 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3463 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3464 if (semaphore_state) {
3465 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003466 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003467 }
3468
3469 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3470 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3471 // 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
3472 // confused itself just as much.
3473 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3474 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3475 // Mark the image as having been released to the WSI
3476 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3477 if (swapchain_data) {
3478 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3479 if (present_id_info) {
3480 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3481 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3482 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003483 }
3484 }
locke-lunargd556cc32019-09-17 01:21:23 -06003485 }
locke-lunargd556cc32019-09-17 01:21:23 -06003486}
3487
3488void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3489 const VkSwapchainCreateInfoKHR *pCreateInfos,
3490 const VkAllocationCallbacks *pAllocator,
3491 VkSwapchainKHR *pSwapchains, VkResult result) {
3492 if (pCreateInfos) {
3493 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003494 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003495 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003496 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3497 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003498 }
3499 }
3500}
3501
3502void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3503 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003504 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003505 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003506 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3507 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003508 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003509 }
3510
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003511 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003512 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003513 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3514 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003515 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003516 }
3517
3518 // Mark the image as acquired.
3519 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3520 if (swapchain_data) {
3521 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003522 }
3523}
3524
3525void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3526 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3527 VkResult result) {
3528 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3529 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3530}
3531
3532void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3533 uint32_t *pImageIndex, VkResult result) {
3534 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3535 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3536 pAcquireInfo->fence, pImageIndex);
3537}
3538
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003539std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3540 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3541}
3542
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003543void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3544 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3545 VkResult result) {
3546 if (result != VK_SUCCESS) {
3547 return;
3548 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003549 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003550 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003551 // this can fail if the allocator fails
3552 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3553 if (result != VK_SUCCESS) {
3554 return;
3555 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003556 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003557 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3558 if (result != VK_SUCCESS) {
3559 return;
3560 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003561
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003562 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003563 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003564 }
3565}
3566
3567// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003568static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003569 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003570}
3571
3572void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3573 uint32_t *pQueueFamilyPropertyCount,
3574 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003575 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3576 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003577 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003578}
3579
3580void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003581 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003582 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3583 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003584 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003585}
3586
3587void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003588 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003589 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3590 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003591 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003592}
3593void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3594 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003595 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003596}
3597
Jeremy Gebben082a9832021-10-28 13:40:11 -06003598void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003599
3600void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3601 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3602 const VkAllocationCallbacks *pAllocator,
3603 VkSurfaceKHR *pSurface, VkResult result) {
3604 if (VK_SUCCESS != result) return;
3605 RecordVulkanSurface(pSurface);
3606}
3607
3608#ifdef VK_USE_PLATFORM_ANDROID_KHR
3609void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3610 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3611 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3612 VkResult result) {
3613 if (VK_SUCCESS != result) return;
3614 RecordVulkanSurface(pSurface);
3615}
3616#endif // VK_USE_PLATFORM_ANDROID_KHR
3617
3618#ifdef VK_USE_PLATFORM_IOS_MVK
3619void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3620 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3621 VkResult result) {
3622 if (VK_SUCCESS != result) return;
3623 RecordVulkanSurface(pSurface);
3624}
3625#endif // VK_USE_PLATFORM_IOS_MVK
3626
3627#ifdef VK_USE_PLATFORM_MACOS_MVK
3628void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3629 const VkMacOSSurfaceCreateInfoMVK *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_MACOS_MVK
3636
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003637#ifdef VK_USE_PLATFORM_METAL_EXT
3638void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3639 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3640 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3641 VkResult result) {
3642 if (VK_SUCCESS != result) return;
3643 RecordVulkanSurface(pSurface);
3644}
3645#endif // VK_USE_PLATFORM_METAL_EXT
3646
locke-lunargd556cc32019-09-17 01:21:23 -06003647#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3648void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3649 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3650 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3651 VkResult result) {
3652 if (VK_SUCCESS != result) return;
3653 RecordVulkanSurface(pSurface);
3654}
3655#endif // VK_USE_PLATFORM_WAYLAND_KHR
3656
3657#ifdef VK_USE_PLATFORM_WIN32_KHR
3658void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3659 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3660 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3661 VkResult result) {
3662 if (VK_SUCCESS != result) return;
3663 RecordVulkanSurface(pSurface);
3664}
3665#endif // VK_USE_PLATFORM_WIN32_KHR
3666
3667#ifdef VK_USE_PLATFORM_XCB_KHR
3668void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *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_XCB_KHR
3675
3676#ifdef VK_USE_PLATFORM_XLIB_KHR
3677void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3678 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3679 VkResult result) {
3680 if (VK_SUCCESS != result) return;
3681 RecordVulkanSurface(pSurface);
3682}
3683#endif // VK_USE_PLATFORM_XLIB_KHR
3684
Niklas Haas8b84af12020-04-19 22:20:11 +02003685void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3686 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3687 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3688 VkResult result) {
3689 if (VK_SUCCESS != result) return;
3690 RecordVulkanSurface(pSurface);
3691}
3692
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003693void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3694 VkSurfaceKHR surface,
3695 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3696 VkResult result) {
3697 if (VK_SUCCESS != result) return;
3698 auto surface_state = Get<SURFACE_STATE>(surface);
3699 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3700}
3701
3702void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3703 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3704 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3705 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003706
3707 if (pSurfaceInfo->surface) {
3708 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3709 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3710 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3711 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3712 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3713 assert(pd_state);
3714 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3715 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003716}
3717
3718void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3719 VkSurfaceKHR surface,
3720 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3721 VkResult result) {
3722 auto surface_state = Get<SURFACE_STATE>(surface);
3723 VkSurfaceCapabilitiesKHR caps{
3724 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3725 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3726 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3727 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3728 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3729 };
3730 surface_state->SetCapabilities(physicalDevice, caps);
3731}
3732
locke-lunargd556cc32019-09-17 01:21:23 -06003733void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3734 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3735 VkBool32 *pSupported, VkResult result) {
3736 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003737 auto surface_state = Get<SURFACE_STATE>(surface);
3738 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3739}
3740
3741void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3742 VkSurfaceKHR surface,
3743 uint32_t *pPresentModeCount,
3744 VkPresentModeKHR *pPresentModes,
3745 VkResult result) {
3746 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3747
3748 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003749 if (surface) {
3750 auto surface_state = Get<SURFACE_STATE>(surface);
3751 surface_state->SetPresentModes(physicalDevice,
3752 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3753 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3754 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3755 assert(pd_state);
3756 pd_state->surfaceless_query_state.present_modes =
3757 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3758 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003759 }
3760}
3761
3762void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3763 uint32_t *pSurfaceFormatCount,
3764 VkSurfaceFormatKHR *pSurfaceFormats,
3765 VkResult result) {
3766 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3767
3768 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003769 if (surface) {
3770 auto surface_state = Get<SURFACE_STATE>(surface);
3771 surface_state->SetFormats(physicalDevice,
3772 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3773 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3774 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3775 assert(pd_state);
3776 pd_state->surfaceless_query_state.formats =
3777 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3778 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003779 }
3780}
3781
3782void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3783 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3784 uint32_t *pSurfaceFormatCount,
3785 VkSurfaceFormat2KHR *pSurfaceFormats,
3786 VkResult result) {
3787 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3788
3789 if (pSurfaceFormats) {
3790 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003791 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3792 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3793 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003794 if (pSurfaceInfo->surface) {
3795 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3796 surface_state->SetFormats(physicalDevice, std::move(fmts));
3797 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3798 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3799 assert(pd_state);
3800 pd_state->surfaceless_query_state.formats = std::move(fmts);
3801 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003802 }
locke-lunargd556cc32019-09-17 01:21:23 -06003803}
3804
locke-lunargd556cc32019-09-17 01:21:23 -06003805void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3806 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003807 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003808 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003809 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3810}
3811
3812void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003813 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003814 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003815 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3816}
3817
3818void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3819 const VkDebugUtilsLabelEXT *pLabelInfo) {
3820 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3821
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003822 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003823 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3824 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003825 cb_state->debug_label = LoggingLabel(pLabelInfo);
3826}
3827
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003828void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3829 uint32_t queueFamilyIndex,
3830 uint32_t *pCounterCount,
3831 VkPerformanceCounterKHR *pCounters) {
3832 if (NULL == pCounters) return;
3833
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003834 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3835 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003836
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003837 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3838 queue_family_counters->counters.resize(*pCounterCount);
3839 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003840
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003841 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003842}
3843
3844void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3845 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3846 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3847 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3848 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3849}
3850
3851void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3852 VkResult result) {
3853 if (result == VK_SUCCESS) performance_lock_acquired = true;
3854}
3855
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003856void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3857 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003858 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003859 cmd_buffer.second->performance_lock_released = true;
3860 }
3861}
3862
locke-lunargd556cc32019-09-17 01:21:23 -06003863void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003864 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003865 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003866 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003867}
3868
3869void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003870 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003871 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003872 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003873}
3874
Mike Schuchardt2df08912020-12-15 16:28:09 -08003875void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3876 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003877 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003878}
3879
Mike Schuchardt2df08912020-12-15 16:28:09 -08003880void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3881 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3882 const VkAllocationCallbacks *pAllocator,
3883 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3884 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003885 if (VK_SUCCESS != result) return;
3886 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3887}
3888
3889void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003890 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3891 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003892 if (VK_SUCCESS != result) return;
3893 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3894}
3895
3896void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003897 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003898 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003899 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3900 assert(template_state);
3901 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003902 // TODO: Record template push descriptor updates
3903 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003904 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003905 }
3906 }
3907}
3908
3909void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3910 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3911 const void *pData) {
3912 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3913}
3914
3915void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003916 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003917 const void *pData) {
3918 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3919}
3920
Mike Schuchardt2df08912020-12-15 16:28:09 -08003921void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3922 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3923 VkPipelineLayout layout, uint32_t set,
3924 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003925 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003926
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003927 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003928 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003929 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003930 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003931 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003932 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003933 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003934 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003935 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003936 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003937 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3938 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003939 }
3940}
3941
3942void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3943 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003944 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003945 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003946 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003947 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003948 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003949 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003950 }
3951}
3952
3953void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3954 uint32_t *pPropertyCount,
3955 VkDisplayPlanePropertiesKHR *pProperties,
3956 VkResult result) {
3957 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3958 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3959}
3960
3961void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3962 uint32_t *pPropertyCount,
3963 VkDisplayPlaneProperties2KHR *pProperties,
3964 VkResult result) {
3965 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3966 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3967}
3968
3969void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3970 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3971 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003972 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003973 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003974 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003975}
3976
3977void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3978 uint32_t query, uint32_t index) {
3979 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003980 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003981 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003982 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003983}
3984
3985void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3986 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003987 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003988
3989 if (create_info->format != VK_FORMAT_UNDEFINED) {
3990 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003991 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003992 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3993 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003994 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003995
Jeremy Gebben082a9832021-10-28 13:40:11 -06003996 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003997}
3998
3999void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4000 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4001 const VkAllocationCallbacks *pAllocator,
4002 VkSamplerYcbcrConversion *pYcbcrConversion,
4003 VkResult result) {
4004 if (VK_SUCCESS != result) return;
4005 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4006}
4007
4008void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4009 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4010 const VkAllocationCallbacks *pAllocator,
4011 VkSamplerYcbcrConversion *pYcbcrConversion,
4012 VkResult result) {
4013 if (VK_SUCCESS != result) return;
4014 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4015}
4016
4017void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4018 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004019 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004020}
4021
4022void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4023 VkSamplerYcbcrConversion ycbcrConversion,
4024 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004025 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004026}
4027
Tony-LunarG977448c2019-12-02 14:52:02 -07004028void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4029 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004030 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004031 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004032
4033 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004034 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004035 if (!query_pool_state) return;
4036
4037 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004038 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4039 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004040 auto query_index = firstQuery + i;
4041 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004042 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004043 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004044 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004045 }
4046 }
locke-lunargd556cc32019-09-17 01:21:23 -06004047 }
4048}
4049
Tony-LunarG977448c2019-12-02 14:52:02 -07004050void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4051 uint32_t queryCount) {
4052 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4053}
4054
4055void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4056 uint32_t queryCount) {
4057 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4058}
4059
locke-lunargd556cc32019-09-17 01:21:23 -06004060void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004061 const UPDATE_TEMPLATE_STATE *template_state,
4062 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004063 // Translate the templated update into a normal update for validation...
4064 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4065 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4066 decoded_update.desc_writes.data(), 0, NULL);
4067}
4068
4069// Update the common AllocateDescriptorSetsData
4070void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004071 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004072 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004073 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004074 if (layout) {
4075 ds_data->layout_nodes[i] = layout;
4076 // Count total descriptors required per type
4077 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4078 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004079 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4080 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004081 }
4082 }
4083 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4084 }
4085}
4086
locke-lunargd556cc32019-09-17 01:21:23 -06004087void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4088 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004089 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004090 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004091}
4092
Tony-LunarG745150c2021-07-02 15:07:31 -06004093void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4094 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4095 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004096 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004097 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004098}
4099
locke-lunargd556cc32019-09-17 01:21:23 -06004100void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4101 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4102 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004103 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004104 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004105}
4106
Tony-LunarG745150c2021-07-02 15:07:31 -06004107void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4108 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4109 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4110 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004111 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004112 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004113}
4114
locke-lunargd556cc32019-09-17 01:21:23 -06004115void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4116 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004117 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004118 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004119 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004120 if (!disabled[command_buffer_state]) {
4121 cb_state->AddChild(buffer_state);
4122 }
locke-lunargd556cc32019-09-17 01:21:23 -06004123}
4124
4125void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4126 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004127 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004128 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004129 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004130 if (!disabled[command_buffer_state]) {
4131 cb_state->AddChild(buffer_state);
4132 }
locke-lunargd556cc32019-09-17 01:21:23 -06004133}
4134
4135void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004136 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004137 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004138}
4139
4140void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4141 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004142 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004143 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004144 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004145 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004146 cb_state->AddChild(buffer_state);
4147 }
locke-lunargd556cc32019-09-17 01:21:23 -06004148}
4149
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004150void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4151 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004152 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004153 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4154}
4155
4156void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4157 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004158 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004159 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4160}
4161
Tony-LunarG977448c2019-12-02 14:52:02 -07004162void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4163 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004164 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004165 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004166 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004167 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004168 auto buffer_state = Get<BUFFER_STATE>(buffer);
4169 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004170 cb_state->AddChild(buffer_state);
4171 cb_state->AddChild(count_buffer_state);
4172 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004173}
4174
locke-lunargd556cc32019-09-17 01:21:23 -06004175void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4176 VkDeviceSize offset, VkBuffer countBuffer,
4177 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4178 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004179 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004180 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004181}
4182
4183void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4184 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4185 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004186 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004187 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004188}
4189
4190void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4191 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004192 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004193 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004194 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004195 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004196 auto buffer_state = Get<BUFFER_STATE>(buffer);
4197 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004198 cb_state->AddChild(buffer_state);
4199 cb_state->AddChild(count_buffer_state);
4200 }
locke-lunargd556cc32019-09-17 01:21:23 -06004201}
4202
4203void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4204 VkDeviceSize offset, VkBuffer countBuffer,
4205 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4206 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004207 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004208 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004209}
4210
4211void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4212 VkDeviceSize offset, VkBuffer countBuffer,
4213 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4214 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004215 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004216 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004217}
4218
4219void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4220 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004221 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004222 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004223}
4224
4225void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4226 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004227 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004228 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004229 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004230 if (!disabled[command_buffer_state] && buffer_state) {
4231 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004232 }
4233}
4234
4235void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4236 VkDeviceSize offset, VkBuffer countBuffer,
4237 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4238 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004239 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004240 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004241 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004242 auto buffer_state = Get<BUFFER_STATE>(buffer);
4243 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004244 if (buffer_state) {
4245 cb_state->AddChild(buffer_state);
4246 }
4247 if (count_buffer_state) {
4248 cb_state->AddChild(count_buffer_state);
4249 }
locke-lunargd556cc32019-09-17 01:21:23 -06004250 }
4251}
4252
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004253void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4254 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4255 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4256 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4257 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4258 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4259 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004260 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004261 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004262 cb_state->hasTraceRaysCmd = true;
4263}
4264
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004265void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4266 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4267 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4268 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4269 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4270 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004271 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004272 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004273 cb_state->hasTraceRaysCmd = true;
4274}
4275
4276void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4277 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4278 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4279 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4280 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4281 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004282 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004283 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004284 cb_state->hasTraceRaysCmd = true;
4285}
4286
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004287std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4288 uint32_t unique_shader_id) const {
4289 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4290 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4291 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4292 : std::make_shared<SHADER_MODULE_STATE>();
4293}
4294
4295std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4296 uint32_t unique_shader_id,
4297 VkShaderModule handle) const {
4298 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4299 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4300 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4301 : std::make_shared<SHADER_MODULE_STATE>();
4302}
4303
locke-lunargd556cc32019-09-17 01:21:23 -06004304void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4305 const VkAllocationCallbacks *pAllocator,
4306 VkShaderModule *pShaderModule, VkResult result,
4307 void *csm_state_data) {
4308 if (VK_SUCCESS != result) return;
4309 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4310
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004311 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004312}
4313
John Zulauf22b0fbe2019-10-15 06:26:16 -06004314void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4315 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4316 VkResult result) {
4317 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004318 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004319
4320 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4321
4322 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004323 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004324 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004325 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004326
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004327 auto format_features = GetImageFormatFeatures(
4328 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4329 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004330
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004331 auto image_state =
4332 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004333 if (!swapchain_image.fake_base_address) {
4334 auto size = image_state->fragment_encoder->TotalSize();
4335 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004336 }
4337
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004338 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004339 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004340 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004341 }
4342 }
4343
4344 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004345 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4346 }
4347}
sourav parmar35e7a002020-06-09 17:58:44 -07004348
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004349void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4350 const VkCopyAccelerationStructureInfoKHR *pInfo,
4351 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004352 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4353 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004354 if (dst_as_state != nullptr && src_as_state != nullptr) {
4355 dst_as_state->built = true;
4356 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4357 }
4358}
4359
sourav parmar35e7a002020-06-09 17:58:44 -07004360void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4361 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004362 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004363 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004364 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004365 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4366 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004367 if (dst_as_state != nullptr && src_as_state != nullptr) {
4368 dst_as_state->built = true;
4369 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004370 if (!disabled[command_buffer_state]) {
4371 cb_state->AddChild(dst_as_state);
4372 cb_state->AddChild(src_as_state);
4373 }
sourav parmar35e7a002020-06-09 17:58:44 -07004374 }
4375 }
4376}
Piers Daniell39842ee2020-07-10 16:42:33 -06004377
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004378void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4379 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4380 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4381 if (cb_state) {
4382 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4383 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4384 if (!disabled[command_buffer_state]) {
4385 cb_state->AddChild(src_as_state);
4386 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004387 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4388 if (dst_buffer) {
4389 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004390 }
4391 }
4392}
4393
4394void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4395 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4396 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4397 if (cb_state) {
4398 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4399 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004400 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4401 if (buffer_state) {
4402 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004403 }
4404 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4405 cb_state->AddChild(dst_as_state);
4406 }
4407 }
4408}
4409
Piers Daniell39842ee2020-07-10 16:42:33 -06004410void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004411 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004412 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004413}
4414
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004415void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4416 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4417 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4418}
4419
Piers Daniell39842ee2020-07-10 16:42:33 -06004420void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004421 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004422 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004423}
4424
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004425void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4426 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4427 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4428}
4429
Piers Daniell39842ee2020-07-10 16:42:33 -06004430void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4431 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004432 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004433 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004434 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004435}
4436
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004437void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4438 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004439 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004440 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4441 cb_state->primitiveTopology = primitiveTopology;
4442}
4443
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004444void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4445 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004446 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4447 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004448 uint32_t bits = (1u << viewportCount) - 1u;
4449 cb_state->viewportWithCountMask |= bits;
4450 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004451 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004452 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004453
4454 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4455 for (size_t i = 0; i < viewportCount; ++i) {
4456 cb_state->dynamicViewports[i] = pViewports[i];
4457 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004458}
4459
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004460void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4461 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004462 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004463}
4464
4465void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004466 const VkViewport *pViewports) {
4467 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004468}
4469
4470void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4471 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004472 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004473 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004474 uint32_t bits = (1u << scissorCount) - 1u;
4475 cb_state->scissorWithCountMask |= bits;
4476 cb_state->trashedScissorMask &= ~bits;
4477 cb_state->scissorWithCountCount = scissorCount;
4478 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004479}
4480
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004481void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4482 const VkRect2D *pScissors) {
4483 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4484}
4485
4486void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4487 const VkRect2D *pScissors) {
4488 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4489}
4490
4491void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4492 uint32_t bindingCount, const VkBuffer *pBuffers,
4493 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4494 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004495 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004496 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004497
4498 uint32_t end = firstBinding + bindingCount;
4499 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4500 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4501 }
4502
4503 for (uint32_t i = 0; i < bindingCount; ++i) {
4504 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004505 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004506 vertex_buffer_binding.offset = pOffsets[i];
4507 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4508 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4509 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004510 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004511 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004512 }
4513 }
4514}
4515
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004516void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4517 uint32_t bindingCount, const VkBuffer *pBuffers,
4518 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4519 const VkDeviceSize *pStrides) {
4520 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4521 CMD_BINDVERTEXBUFFERS2EXT);
4522}
4523
4524void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4525 uint32_t bindingCount, const VkBuffer *pBuffers,
4526 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4527 const VkDeviceSize *pStrides) {
4528 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4529 CMD_BINDVERTEXBUFFERS2);
4530}
4531
Piers Daniell39842ee2020-07-10 16:42:33 -06004532void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004533 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004534 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004535}
4536
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004537void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4538 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4539 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4540}
4541
Piers Daniell39842ee2020-07-10 16:42:33 -06004542void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004543 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004544 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004545}
4546
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004547void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4548 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4549 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4550}
4551
Piers Daniell39842ee2020-07-10 16:42:33 -06004552void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004553 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004554 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004555}
4556
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004557void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4558 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4559 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4560}
4561
Piers Daniell39842ee2020-07-10 16:42:33 -06004562void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4563 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004564 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004565 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004566}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004567
4568void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4569 VkBool32 depthBoundsTestEnable) {
4570 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4571 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4572}
4573
Piers Daniell39842ee2020-07-10 16:42:33 -06004574void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004575 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004576 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004577}
4578
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004579void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4580 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4581 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4582}
4583
Piers Daniell39842ee2020-07-10 16:42:33 -06004584void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4585 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4586 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004587 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004588 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004589}
locke-lunarg4189aa22020-10-21 00:23:48 -06004590
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004591void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4592 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4593 VkCompareOp compareOp) {
4594 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4595 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4596}
4597
locke-lunarg4189aa22020-10-21 00:23:48 -06004598void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4599 uint32_t discardRectangleCount,
4600 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004601 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004602 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004603}
4604
4605void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4606 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004607 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004608 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004609}
4610
4611void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4612 VkCoarseSampleOrderTypeNV sampleOrderType,
4613 uint32_t customSampleOrderCount,
4614 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004615 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004616 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004617}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004618
4619void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
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_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004622}
4623
4624void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004625 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004626 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004627}
4628
4629void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4630 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004631 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004632 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004633}
4634
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004635void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4636 VkBool32 rasterizerDiscardEnable) {
4637 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4638 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4639}
4640
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004641void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004642 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004643 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004644}
4645
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004646void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4647 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4648 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4649}
4650
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004651void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4652 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004653 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004654 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004655}
Piers Daniell924cd832021-05-18 13:48:47 -06004656
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004657void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4658 VkBool32 primitiveRestartEnable) {
4659 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4660 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4661}
4662
Piers Daniell924cd832021-05-18 13:48:47 -06004663void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4664 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4665 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4666 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004667 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004668 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4669
4670 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4671 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4672 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004673 const auto *dynamic_state = pipeline_state->DynamicState();
4674 if (dynamic_state) {
4675 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4676 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004677 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4678 break;
4679 }
4680 }
4681 }
4682 }
4683 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004684}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004685
ziga-lunarg67b7c392022-03-26 01:45:34 +01004686void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4687 const VkBool32 *pColorWriteEnables) {
4688 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4689 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4690 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4691}
4692
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004693void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004694 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004695 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004696 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004697 // address is used for GPU-AV and ray tracing buffer validation
4698 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004699 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004700 }
4701}
4702
4703void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4704 VkDeviceAddress address) {
4705 RecordGetBufferDeviceAddress(pInfo, address);
4706}
4707
4708void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4709 VkDeviceAddress address) {
4710 RecordGetBufferDeviceAddress(pInfo, address);
4711}
4712
4713void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4714 VkDeviceAddress address) {
4715 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004716}
4717
4718std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4719 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004720 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004721}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004722
4723std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4724 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004725 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004726 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4727}