blob: 895a0289dc790ed92da7c0df13b542acfb05ce68 [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Tobias Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Dave Houlton <daveh@lunarg.com>
21 * Shannon McPherson <shannon@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
28#include "vk_enum_string_helper.h"
29#include "vk_format_utils.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33#include "vk_typemap_helper.h"
34
35#include "chassis.h"
36#include "state_tracker.h"
37#include "shader_validation.h"
Jeremy Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = {
138 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
139 nullptr,
140 };
141
142 // Find the image modifier
143 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
144
145 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
146 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
147 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
148
149 // Second query to have all the modifiers filled
150 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
151
152 // Look for the image modifier in the list
153 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
154 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
155 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
156 break;
157 }
158 }
159 } else {
160 format_features =
161 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
162 }
163 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600164 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
165 nullptr};
166 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200167
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
169 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
170 nullptr};
171 format_properties_2.pNext = (void *)&drm_properties_list;
172 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
173 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
174 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
175 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
176 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200177
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600178 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
179 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
180 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
181 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200182 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200183 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600184 } else {
185 VkFormatProperties format_properties;
186 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
187 format_features =
188 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200189 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600190 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200191}
192
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700193std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
194 VkFormatFeatureFlags2KHR features) {
195 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, features);
196}
197
198std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
199 VkSwapchainKHR swapchain, uint32_t swapchain_index,
200 VkFormatFeatureFlags2KHR features) {
201 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, swapchain, swapchain_index, features);
202}
203
locke-lunargd556cc32019-09-17 01:21:23 -0600204void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
205 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
206 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200207 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700208 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600209 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600210 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600211 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200212 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
213 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
214 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600215 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700216 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600217}
218
219void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600220 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600221}
222
223void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
224 VkImageLayout imageLayout, const VkClearColorValue *pColor,
225 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600226 if (disabled[command_buffer_state]) return;
227
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700228 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600229 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600230 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600231 }
232}
233
234void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
235 VkImageLayout imageLayout,
236 const VkClearDepthStencilValue *pDepthStencil,
237 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600238 if (disabled[command_buffer_state]) return;
239
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700240 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600241 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600242 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600243 }
244}
245
246void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
247 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
248 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600252 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600253}
254
Jeff Leger178b1e52020-10-05 12:22:23 -0400255void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
256 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600257 if (disabled[command_buffer_state]) return;
258
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700259 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600260 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
261 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400262}
263
Tony-LunarGb61514a2021-11-02 12:36:51 -0600264void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
265 if (disabled[command_buffer_state]) return;
266
267 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
268 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
269 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
270}
271
locke-lunargd556cc32019-09-17 01:21:23 -0600272void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
273 VkImageLayout srcImageLayout, VkImage dstImage,
274 VkImageLayout dstImageLayout, uint32_t regionCount,
275 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600276 if (disabled[command_buffer_state]) return;
277
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700278 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600279 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600280}
281
Jeff Leger178b1e52020-10-05 12:22:23 -0400282void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
283 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600284 if (disabled[command_buffer_state]) return;
285
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700286 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600287 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
288 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400289}
290
Tony-LunarG562fc102021-11-12 13:58:35 -0700291void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
292 const VkResolveImageInfo2 *pResolveImageInfo) {
293 if (disabled[command_buffer_state]) return;
294
295 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
296 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
297 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
298}
299
locke-lunargd556cc32019-09-17 01:21:23 -0600300void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
301 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
302 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600303 if (disabled[command_buffer_state]) return;
304
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700305 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600306 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600307}
308
Jeff Leger178b1e52020-10-05 12:22:23 -0400309void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
310 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600311 if (disabled[command_buffer_state]) return;
312
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700313 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600314 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
315 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400316}
317
Tony-LunarG542ae912021-11-04 16:06:44 -0600318void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
319 if (disabled[command_buffer_state]) return;
320
321 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
322 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
323 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
324}
325
locke-lunargd556cc32019-09-17 01:21:23 -0600326void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
327 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
328 VkResult result) {
329 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600330
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600331 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600332
James Rumble2f6e7bb2021-07-13 15:21:20 +0100333 if (pCreateInfo) {
334 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700335 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700336 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100337 // address is used for GPU-AV and ray tracing buffer validation
338 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700339 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100340 }
341 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600342 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600343}
344
345void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
346 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
347 VkResult result) {
348 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600349
Jeremy Gebben9f537102021-10-05 16:37:12 -0600350 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600351
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200352 VkFormatFeatureFlags2KHR buffer_features;
353 if (has_format_feature2) {
354 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
355 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
356 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
357 buffer_features = fmt_props_3.bufferFeatures;
358 } else {
359 VkFormatProperties format_properties;
360 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
361 buffer_features = format_properties.bufferFeatures;
362 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600363
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200364 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600365}
366
367void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
368 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
369 VkResult result) {
370 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600371 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700372
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200373 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600374 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700375 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600376 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700377 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200378 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
379 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
380 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700381 }
382
locke-lunarg9939d4b2020-10-26 20:11:08 -0600383 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600384 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600385 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700386 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600387 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700388 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600389 image_format_info.type = image_state->createInfo.imageType;
390 image_format_info.format = image_state->createInfo.format;
391 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600392 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
393 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600394 image_format_info.flags = image_state->createInfo.flags;
395
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600396 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600397
398 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
399 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600400
Jeremy Gebben082a9832021-10-28 13:40:11 -0600401 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600402}
403
404void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
405 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600406 if (disabled[command_buffer_state]) return;
407
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700408 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600409 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600410}
411
Jeff Leger178b1e52020-10-05 12:22:23 -0400412void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600413 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600414 if (disabled[command_buffer_state]) return;
415
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700416 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600417 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
418 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400419}
420
Tony-LunarGef035472021-11-02 10:23:33 -0600421void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
422 if (disabled[command_buffer_state]) return;
423
424 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
425 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
426 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
427}
428
locke-lunargd556cc32019-09-17 01:21:23 -0600429void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
430 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600431 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600432}
433
434void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700435 auto buffer_state = Get<BUFFER_STATE>(buffer);
436 if (buffer_state) {
437 WriteLockGuard guard(buffer_address_lock_);
438 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
439 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600440 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600441}
442
443void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
444 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600445 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600446}
447
448void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
449 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600450 if (disabled[command_buffer_state]) return;
451
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700452 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600453 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600454}
455
456void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
457 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
458 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600459 if (disabled[command_buffer_state]) return;
460
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700461 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600462
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600463 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600464}
465
Jeff Leger178b1e52020-10-05 12:22:23 -0400466void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
467 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600468 if (disabled[command_buffer_state]) return;
469
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700470 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600471 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
472 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400473}
474
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700475void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
476 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
477 if (disabled[command_buffer_state]) return;
478
479 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
480 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
481 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
482}
483
locke-lunargd556cc32019-09-17 01:21:23 -0600484void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
485 VkImageLayout dstImageLayout, uint32_t regionCount,
486 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600487 if (disabled[command_buffer_state]) return;
488
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700489 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600490 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600491}
492
Jeff Leger178b1e52020-10-05 12:22:23 -0400493void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
494 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600495 if (disabled[command_buffer_state]) return;
496
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700497 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600498 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
499 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400500}
501
Tony Barbour845d29b2021-11-09 11:43:14 -0700502void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
503 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
504 if (disabled[command_buffer_state]) return;
505
506 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
507 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
508 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
509}
510
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700511// Gets union of all features defined by Potential Format Features
512// except, does not handle the external format case for AHB as that only can be used for sampled images
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200513VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
514 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700515
516 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200517 if (has_format_feature2) {
518 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200519 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
520 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200521 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100522
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200523 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100524
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200525 format_features |= fmt_props_3.linearTilingFeatures;
526 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100527
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200528 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
529 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
530 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
531 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
532 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100533
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200534 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
535 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
536 }
537 }
538 } else {
539 VkFormatProperties format_properties;
540 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
541 format_features |= format_properties.linearTilingFeatures;
542 format_features |= format_properties.optimalTilingFeatures;
543
544 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
545 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
546 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
547
548 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
549
550 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
551 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
552 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
553 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
554
555 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
556 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
557 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700558 }
559 }
560 }
561
562 return format_features;
563}
564
locke-lunargd556cc32019-09-17 01:21:23 -0600565void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
566 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
567 VkResult result) {
568 if (VK_SUCCESS != result) return;
569
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600570 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600571 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
572 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600573 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600574
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600575 device_state->instance_state = this;
576 // Save local link to this device's physical device state
577 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
578 // finish setup in the object representing the device
579 device_state->CreateDevice(pCreateInfo);
580}
581
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -0600582std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags) {
583 return std::make_shared<QUEUE_STATE>(q, index, flags);
584}
585
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600586void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600587 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
588 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700589 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600590 if (features2) {
591 enabled_features_found = &(features2->features);
592 }
593 }
594
locke-lunargd556cc32019-09-17 01:21:23 -0600595 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600596 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600597 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600598 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600599 }
600
Tony-LunarG273f32f2021-09-28 08:56:30 -0600601 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
602 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600603 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600604 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600605 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600606 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
607 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600608 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600609 }
610
611 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
612 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600613 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
614 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600615 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
616 }
617
618 const auto *pipeline_creation_cache_control_features =
619 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
620 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600621 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600622 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
623 }
624
625 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
626 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600627 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600628 }
629
630 const auto *demote_to_helper_invocation_features =
631 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
632 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600633 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600634 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
635 }
636
637 const auto *terminate_invocation_features =
638 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
639 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600640 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600641 }
642
643 const auto *subgroup_size_control_features =
644 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
645 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600646 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
647 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600648 }
649
650 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
651 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600652 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600653 }
654
655 const auto *texture_compression_astchdr_features =
656 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
657 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600658 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600659 }
660
661 const auto *initialize_workgroup_memory_features =
662 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
663 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600664 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600665 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
666 }
667
668 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
669 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600670 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600671 }
672
673 const auto *shader_integer_dot_product_features =
674 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
675 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600676 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600677 }
678
679 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
680 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600681 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600682 }
683 }
684
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700685 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700686 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600687 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700688 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700689 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600690 enabled_features.core12.drawIndirectCount = VK_FALSE;
691 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
692 enabled_features.core12.descriptorIndexing = VK_FALSE;
693 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
694 enabled_features.core12.shaderOutputLayer = VK_FALSE;
695 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
696 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700697
698 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700699
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700700 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700701 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600702 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
703 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700704 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600705 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700706 }
707
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700708 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700709 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600710 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
711 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700712 }
713
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700714 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700715 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600716 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700717 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600718 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700719 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600720 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700721 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700723 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700725 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600726 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700727 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600728 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700729 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600730 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700731 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600732 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700733 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700735 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600738 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700739 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600740 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700741 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700743 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700745 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600746 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700747 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600748 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700749 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600750 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
751 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700752 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600753 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700754 }
755
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700756 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700757 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600758 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 }
760
761 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700762 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700763 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600764 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 }
766
767 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700768 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700769 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600770 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700771 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700772 }
773
774 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700775 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700776 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600777 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 }
779
780 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700781 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700782 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600783 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700784 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700785 }
786
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700787 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700788 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600789 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700790 }
791
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700792 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700793 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600794 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700795 }
796
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700797 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700798 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600799 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
800 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
801 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700802 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800803
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700804 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800805 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600806 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
807 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800808 }
809
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700810 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800811 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600812 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
813 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
814 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800815 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
816 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700817 }
818
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700819 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600821 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700822 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700823 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700824
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700825 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700826 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600827 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
828 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700829 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600830 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
831 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700832 }
833
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700834 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700835 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600836 enabled_features.core11.multiview = multiview_features->multiview;
837 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
838 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700839 }
840
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700841 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700842 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600843 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
844 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700845 }
846
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700847 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700848 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600849 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700850 }
851
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700852 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700853 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600854 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 }
856
857 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700858 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700859 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600860 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700861 }
862 }
863
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700864 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600865 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600866 physical_device_count = device_group_ci->physicalDeviceCount;
867 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600868 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600869 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600870 }
locke-lunargd556cc32019-09-17 01:21:23 -0600871
sfricke-samsung828e59d2021-08-22 23:20:49 -0700872 // Features from other extensions passesd in create info
873 {
874 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
875 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600876 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700877 }
locke-lunargd556cc32019-09-17 01:21:23 -0600878
sfricke-samsung828e59d2021-08-22 23:20:49 -0700879 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
880 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600881 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700882 }
locke-lunargd556cc32019-09-17 01:21:23 -0600883
sfricke-samsung828e59d2021-08-22 23:20:49 -0700884 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
885 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600886 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700887 }
locke-lunargd556cc32019-09-17 01:21:23 -0600888
sfricke-samsung828e59d2021-08-22 23:20:49 -0700889 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
890 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600891 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700892 }
locke-lunargd556cc32019-09-17 01:21:23 -0600893
sfricke-samsung828e59d2021-08-22 23:20:49 -0700894 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
895 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600896 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700897 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700898
sfricke-samsung828e59d2021-08-22 23:20:49 -0700899 const auto *buffer_device_address_ext_features =
900 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
901 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600902 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700903 }
locke-lunargd556cc32019-09-17 01:21:23 -0600904
sfricke-samsung828e59d2021-08-22 23:20:49 -0700905 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
906 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600907 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700908 }
locke-lunargd556cc32019-09-17 01:21:23 -0600909
sfricke-samsung828e59d2021-08-22 23:20:49 -0700910 const auto *compute_shader_derivatives_features =
911 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
912 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600913 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700914 }
locke-lunargd556cc32019-09-17 01:21:23 -0600915
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 const auto *fragment_shader_barycentric_features =
917 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
918 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600919 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700920 }
locke-lunargd556cc32019-09-17 01:21:23 -0600921
sfricke-samsung828e59d2021-08-22 23:20:49 -0700922 const auto *shader_image_footprint_features =
923 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
924 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600925 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700926 }
locke-lunargd556cc32019-09-17 01:21:23 -0600927
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 const auto *fragment_shader_interlock_features =
929 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
930 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600931 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700932 }
locke-lunargd556cc32019-09-17 01:21:23 -0600933
sfricke-samsung828e59d2021-08-22 23:20:49 -0700934 const auto *texel_buffer_alignment_features =
935 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
936 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600937 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700938 }
locke-lunargd556cc32019-09-17 01:21:23 -0600939
sfricke-samsung828e59d2021-08-22 23:20:49 -0700940 const auto *pipeline_exe_props_features =
941 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
942 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600943 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700944 }
locke-lunargd556cc32019-09-17 01:21:23 -0600945
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 const auto *dedicated_allocation_image_aliasing_features =
947 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
948 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600949 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700950 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500951
sfricke-samsung828e59d2021-08-22 23:20:49 -0700952 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
953 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600954 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700955 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100956
sfricke-samsung828e59d2021-08-22 23:20:49 -0700957 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
958 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600959 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700960 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000961
sfricke-samsung828e59d2021-08-22 23:20:49 -0700962 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
963 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600964 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700965 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800966
sfricke-samsung828e59d2021-08-22 23:20:49 -0700967 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
968 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600969 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700970 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700971
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 const auto *ray_tracing_pipeline_features =
973 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
974 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600975 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700976 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700977
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 const auto *ray_tracing_acceleration_structure_features =
979 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
980 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600981 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700982 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500983
sfricke-samsung828e59d2021-08-22 23:20:49 -0700984 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
985 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600986 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700987 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500988
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 const auto *fragment_density_map_features =
990 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
991 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600992 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700993 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200994
sfricke-samsung828e59d2021-08-22 23:20:49 -0700995 const auto *fragment_density_map_features2 =
996 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
997 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600998 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700999 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001000
Agarwal, Arpit78509112022-02-17 15:29:05 -07001001 const auto *fragment_density_map_offset_features =
1002 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
1003 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001004 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001005 }
1006
sfricke-samsung828e59d2021-08-22 23:20:49 -07001007 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1008 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001009 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001010 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001011
sfricke-samsung828e59d2021-08-22 23:20:49 -07001012 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1013 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001014 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001015 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001016
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 const auto *fragment_shading_rate_features =
1018 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1019 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001020 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001021 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001022
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001023 const auto *fragment_shading_rate_enums_features =
1024 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1025 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001026 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001027 }
1028
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 const auto *extended_dynamic_state_features =
1030 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1031 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001032 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001033 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001034
sfricke-samsung828e59d2021-08-22 23:20:49 -07001035 const auto *extended_dynamic_state2_features =
1036 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1037 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001038 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001039 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001040
sfricke-samsung828e59d2021-08-22 23:20:49 -07001041 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1042 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001043 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001044 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001045
sfricke-samsung828e59d2021-08-22 23:20:49 -07001046 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1047 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001048 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001049 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001050
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 const auto *shader_integer_functions2_features =
1052 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1053 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001054 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001055 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001056
sfricke-samsung828e59d2021-08-22 23:20:49 -07001057 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1058 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001059 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001060 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001061
sfricke-samsung828e59d2021-08-22 23:20:49 -07001062 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1063 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001064 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001065 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001066
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 const auto *shader_image_atomic_int64_features =
1068 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1069 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001070 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001071 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001072
sfricke-samsung828e59d2021-08-22 23:20:49 -07001073 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1074 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001075 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001076 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001077
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 const auto *conditional_rendering_features =
1079 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1080 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001081 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001082 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001083
sfricke-samsung828e59d2021-08-22 23:20:49 -07001084 const auto *workgroup_memory_explicit_layout_features =
1085 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1086 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001087 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001088 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001089
sfricke-samsung828e59d2021-08-22 23:20:49 -07001090 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1091 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001092 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001093 }
Locke Linf3873542021-04-26 11:25:10 -06001094
sfricke-samsung828e59d2021-08-22 23:20:49 -07001095 const auto *vertex_input_dynamic_state_features =
1096 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1097 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001098 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001099 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001100
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 const auto *inherited_viewport_scissor_features =
1102 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1103 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001104 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001105 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001106
sfricke-samsung828e59d2021-08-22 23:20:49 -07001107 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1108 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001109 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001110 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001111
sfricke-samsung828e59d2021-08-22 23:20:49 -07001112 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1113 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001114 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001115 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001116
sfricke-samsung828e59d2021-08-22 23:20:49 -07001117 const auto *shader_atomic_float2_features =
1118 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1119 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001120 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001121 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001122
sfricke-samsung828e59d2021-08-22 23:20:49 -07001123 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1124 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001125 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001126 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001127
sfricke-samsung828e59d2021-08-22 23:20:49 -07001128 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1129 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001130 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001131 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001132
1133 const auto *ray_tracing_motion_blur_features =
1134 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1135 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001136 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001137 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001138
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001139 const auto *primitive_topology_list_restart_features =
1140 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1141 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001142 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001143 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001144
ziga-lunarge1988962021-09-16 13:32:34 +02001145 const auto *zero_initialize_work_group_memory_features =
1146 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1147 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001148 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001149 }
1150
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001151 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1152 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001153 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001154 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001155
Tony-LunarG69604c42021-11-22 16:00:12 -07001156 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1157 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001158 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001159 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001160
1161 const auto *primitives_generated_query_features =
1162 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1163 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001164 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001165 }
Tony-LunarGbe956362022-04-05 13:34:31 -06001166
1167 const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
1168 if (image_2d_view_of_3d_features) {
1169 enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
1170 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001171 }
1172
locke-lunargd556cc32019-09-17 01:21:23 -06001173 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001174 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1175 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001176
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001177 {
1178 uint32_t n_props = 0;
1179 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001180 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001181 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001182 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001183
1184 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001185 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001186 }
1187
1188 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1189 // a path to grab that information from the physical device. This
1190 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1191 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001192 has_format_feature2 =
1193 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1194 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001195 }
1196
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001197 const auto &dev_ext = device_extensions;
1198 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001199
Tony-LunarG273f32f2021-09-28 08:56:30 -06001200 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1201 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001202 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1203 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001204 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001205 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001206 } else {
1207 // VkPhysicalDeviceVulkan11Properties
1208 //
1209 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1210
1211 if (dev_ext.vk_khr_multiview) {
1212 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001213 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1214 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1215 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001216 }
1217
1218 if (dev_ext.vk_khr_maintenance3) {
1219 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001220 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1221 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1222 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001223 }
1224
1225 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001226 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001227 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1228 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1229 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001230 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001231
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001232 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1233 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1234 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1235 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001236
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001237 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001238 }
1239
1240 // VkPhysicalDeviceVulkan12Properties
1241 //
1242 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1243
1244 if (dev_ext.vk_ext_descriptor_indexing) {
1245 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001246 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1247 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001248 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001249 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001250 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001251 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001252 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001253 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001254 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001255 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001256 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001257 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001258 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001259 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1260 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1261 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001262 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001263 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001264 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001265 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001266 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001267 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001268 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001269 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001270 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001271 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001272 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001273 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001274 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001275 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001276 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001277 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001278 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001279 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001280 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001281 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001282 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001283 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001284 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001285 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001286 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001287 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001288 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001289 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001290 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1291 }
1292
1293 if (dev_ext.vk_khr_depth_stencil_resolve) {
1294 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001295 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1296 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1297 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1298 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1299 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001300 }
1301
1302 if (dev_ext.vk_khr_timeline_semaphore) {
1303 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001304 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1305 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1307 }
1308
1309 if (dev_ext.vk_ext_sampler_filter_minmax) {
1310 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001311 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1312 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001313 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001314 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001315 }
1316
1317 if (dev_ext.vk_khr_shader_float_controls) {
1318 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001319 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1320 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1321 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1322 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001323 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001324 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001325 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001326 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001327 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001328 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1329 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1330 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1331 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1332 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1333 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1334 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1335 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1336 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1337 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1338 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1339 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001340 }
locke-lunargd556cc32019-09-17 01:21:23 -06001341 }
1342
sfricke-samsung828e59d2021-08-22 23:20:49 -07001343 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001344 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1345 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1346 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1347 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1348 &phys_dev_props->inline_uniform_block_props);
1349 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1350 &phys_dev_props->vtx_attrib_divisor_props);
1351 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1352 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1353 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1354 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1355 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1356 &phys_dev_props->texel_buffer_alignment_props);
1357 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1358 &phys_dev_props->fragment_density_map_props);
1359 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1360 &phys_dev_props->fragment_density_map2_props);
1361 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001362 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001363 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1364 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1365 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1366 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1367 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1368 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1369 &phys_dev_props->fragment_shading_rate_props);
1370 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1371 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1372 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1373 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1374 &phys_dev_props->blend_operation_advanced_props);
1375 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1376 &phys_dev_props->conservative_rasterization_props);
1377 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1378 &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001379
sfricke-samsung45996a42021-09-16 13:45:27 -07001380 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001381 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001382 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1383 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001384 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1385 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001386
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001387 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001388 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1389 NULL);
1390 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001391
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001392 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1393 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001394 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001395
locke-lunargd556cc32019-09-17 01:21:23 -06001396 // Store queue family data
1397 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1398 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001399 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001400 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1401 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001402 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001403 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001404 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001405 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1406 VkQueue queue = VK_NULL_HANDLE;
1407 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1408 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1409 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1410 get_info.flags = queue_info.flags;
1411 get_info.queueFamilyIndex = queue_info.queue_family_index;
1412 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001413 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001414 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001415 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001416 }
1417 assert(queue != VK_NULL_HANDLE);
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001418 Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001419 }
locke-lunargd556cc32019-09-17 01:21:23 -06001420 }
1421 }
1422}
1423
1424void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1425 if (!device) return;
1426
Jeremy Gebbend177d922021-10-28 13:42:10 -06001427 command_pool_map_.clear();
1428 assert(command_buffer_map_.empty());
1429 pipeline_map_.clear();
1430 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001431
1432 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001433 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001434 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001435 assert(descriptor_set_map_.empty());
1436 desc_template_map_.clear();
1437 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001438 // Because swapchains are associated with Surfaces, which are at instance level,
1439 // they need to be explicitly destroyed here to avoid continued references to
1440 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001441 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001442 entry.second->Destroy();
1443 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001444 swapchain_map_.clear();
1445 image_view_map_.clear();
1446 image_map_.clear();
1447 buffer_view_map_.clear();
1448 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001449 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001450 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001451}
1452
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001453void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1454 VkFence fence, VkResult result) {
1455 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001456 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001457
Jeremy Gebben57642982021-09-14 14:14:55 -06001458 uint64_t early_retire_seq = 0;
1459
1460 if (submitCount == 0) {
1461 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001462 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001463 early_retire_seq = queue_state->Submit(std::move(submission));
1464 }
locke-lunargd556cc32019-09-17 01:21:23 -06001465
1466 // Now process each individual submit
1467 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001468 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001469 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001470 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001471 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001472 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001473 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1474 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1475 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1476 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001477 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001478 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001479
locke-lunargd556cc32019-09-17 01:21:23 -06001480 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001481 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001482 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1483 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1484 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1485 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001486 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001487 }
1488
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001489 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001490 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001491
locke-lunargd556cc32019-09-17 01:21:23 -06001492 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001493 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1494 if (cb_state) {
1495 submission.AddCommandBuffer(std::move(cb_state));
1496 }
locke-lunargd556cc32019-09-17 01:21:23 -06001497 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001498 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001499 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001500 }
1501 auto submit_seq = queue_state->Submit(std::move(submission));
1502 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001503 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001504
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001505 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001506 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001507 }
1508}
1509
Tony-LunarG26fe2842021-11-16 14:07:59 -07001510void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1511 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001512 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001513 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001514 uint64_t early_retire_seq = 0;
1515 if (submitCount == 0) {
1516 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001517 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001518 early_retire_seq = queue_state->Submit(std::move(submission));
1519 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001520
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001521 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1522 CB_SUBMISSION submission;
1523 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001524 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1525 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001526 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001527 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001528 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1529 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001530 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001531 }
1532 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1533 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1534
1535 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001536 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001537 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001538 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001539 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001540 }
1541 auto submit_seq = queue_state->Submit(std::move(submission));
1542 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001543 }
locke-lunargd556cc32019-09-17 01:21:23 -06001544 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001545 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001546 }
1547}
1548
Tony-LunarG26fe2842021-11-16 14:07:59 -07001549void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1550 VkFence fence, VkResult result) {
1551 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1552}
1553
1554void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1555 VkFence fence, VkResult result) {
1556 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1557}
1558
locke-lunargd556cc32019-09-17 01:21:23 -06001559void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1560 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1561 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001562 if (VK_SUCCESS != result) {
1563 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001564 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001565 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1566 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1567 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1568
1569 layer_data::optional<DedicatedBinding> dedicated_binding;
1570
1571 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1572 if (dedicated) {
1573 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001574 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001575 assert(buffer_state);
1576 if (!buffer_state) {
1577 return;
1578 }
1579 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1580 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001581 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001582 assert(image_state);
1583 if (!image_state) {
1584 return;
1585 }
1586 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1587 }
1588 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001589 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1590 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001591 return;
1592}
1593
1594void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001595 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001596 if (mem_info) {
1597 fake_memory.Free(mem_info->fake_base_address);
1598 }
1599 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001600}
1601
1602void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1603 VkFence fence, VkResult result) {
1604 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001605 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001606
Jeremy Gebben57642982021-09-14 14:14:55 -06001607 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001608
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001609 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1610 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001611 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001612 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1613 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1614 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001615 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001616 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001617 if (buffer_state && mem_state) {
1618 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1619 }
locke-lunargd556cc32019-09-17 01:21:23 -06001620 }
1621 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001622 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1623 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1624 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001625 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001626 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001627 if (image_state && mem_state) {
1628 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1629 }
locke-lunargd556cc32019-09-17 01:21:23 -06001630 }
1631 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001632 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1633 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1634 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001635 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1636 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001637 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001638 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001639 if (image_state && mem_state) {
1640 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1641 }
locke-lunargd556cc32019-09-17 01:21:23 -06001642 }
1643 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001644 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001645 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001646 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001647 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001648 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001649 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001650 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001651 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001652 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001653 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001654 auto submit_seq = queue_state->Submit(std::move(submission));
1655 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001656 }
1657
1658 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001659 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001660 }
1661}
1662
1663void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1664 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1665 VkResult result) {
1666 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001667 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001668}
1669
Mike Schuchardt2df08912020-12-15 16:28:09 -08001670void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1671 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001672 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1673 if (semaphore_state) {
1674 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001675 }
1676}
1677
Mike Schuchardt2df08912020-12-15 16:28:09 -08001678void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001679 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001680 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001681 if (semaphore_state) {
1682 semaphore_state->RetireTimeline(pSignalInfo->value);
1683 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001684}
1685
locke-lunargd556cc32019-09-17 01:21:23 -06001686void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001687 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001688 if (mem_info) {
1689 mem_info->mapped_range.offset = offset;
1690 mem_info->mapped_range.size = size;
1691 mem_info->p_driver_data = *ppData;
1692 }
1693}
1694
locke-lunargd556cc32019-09-17 01:21:23 -06001695void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1696 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1697 if (VK_SUCCESS != result) return;
1698
1699 // When we know that all fences are complete we can clean/remove their CBs
1700 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1701 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001702 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001703 if (fence_state) {
1704 fence_state->Retire();
1705 }
locke-lunargd556cc32019-09-17 01:21:23 -06001706 }
1707 }
1708 // NOTE : Alternate case not handled here is when some fences have completed. In
1709 // this case for app to guarantee which fences completed it will have to call
1710 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1711}
1712
John Zulauff89de662020-04-13 18:57:34 -06001713void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1714 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001715 if (VK_SUCCESS != result) return;
1716
Jeremy Gebben15332642021-12-15 19:33:15 -07001717 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1718 // the application calls vkGetSemaphoreCounterValue() on each of them.
1719 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1720 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1721 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1722 if (semaphore_state) {
1723 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1724 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001725 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001726 }
1727}
1728
John Zulauff89de662020-04-13 18:57:34 -06001729void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1730 VkResult result) {
1731 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1732}
1733
1734void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1735 uint64_t timeout, VkResult result) {
1736 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1737}
1738
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001739void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1740 VkResult result) {
1741 if (VK_SUCCESS != result) return;
1742
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001743 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001744 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001745 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001746 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001747}
1748
1749void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1750 VkResult result) {
1751 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1752}
1753void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1754 VkResult result) {
1755 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1756}
1757
locke-lunargd556cc32019-09-17 01:21:23 -06001758void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1759 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001760 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001761 if (fence_state) {
1762 fence_state->Retire();
1763 }
locke-lunargd556cc32019-09-17 01:21:23 -06001764}
1765
Yilong Lice03a312022-01-02 02:08:35 -08001766void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1767 if (Get<QUEUE_STATE>(queue) == nullptr) {
Jeremy Gebbenfcfc33c2022-03-28 15:31:29 -06001768 Add(CreateQueue(queue, queue_family_index, flags));
Yilong Lice03a312022-01-02 02:08:35 -08001769 }
1770}
1771
1772void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1773 VkQueue *pQueue) {
1774 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1775}
1776
1777void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1778 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1779}
1780
locke-lunargd556cc32019-09-17 01:21:23 -06001781void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1782 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001783 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001784 if (queue_state) {
1785 queue_state->Retire();
1786 }
locke-lunargd556cc32019-09-17 01:21:23 -06001787}
1788
1789void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1790 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001791 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001792 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001793 }
1794}
1795
1796void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001797 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001798}
1799
1800void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1801 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001802 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001803}
1804
1805void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001806 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001807}
1808
1809void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1810 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001811 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001812}
1813
locke-lunargd556cc32019-09-17 01:21:23 -06001814void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001815 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001816 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001817 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001818 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001819 if (mem_state) {
1820 buffer_state->SetMemBinding(mem_state, memoryOffset);
1821 }
locke-lunargd556cc32019-09-17 01:21:23 -06001822 }
1823}
1824
1825void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1826 VkDeviceSize memoryOffset, VkResult result) {
1827 if (VK_SUCCESS != result) return;
1828 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1829}
1830
1831void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001832 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001833 for (uint32_t i = 0; i < bindInfoCount; i++) {
1834 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1835 }
1836}
1837
1838void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001839 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001840 for (uint32_t i = 0; i < bindInfoCount; i++) {
1841 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1842 }
1843}
1844
Spencer Fricke6c127102020-04-16 06:25:20 -07001845void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001846 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001847 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001848 buffer_state->memory_requirements_checked = true;
1849 }
1850}
1851
1852void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1853 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001854 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001855}
1856
1857void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001858 const VkBufferMemoryRequirementsInfo2 *pInfo,
1859 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001860 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001861}
1862
1863void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001864 const VkBufferMemoryRequirementsInfo2 *pInfo,
1865 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001866 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001867}
1868
Spencer Fricke6c127102020-04-16 06:25:20 -07001869void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001870 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001871 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001872 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001873 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001874 if (plane_info != nullptr) {
1875 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001876 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001877 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001878 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001879 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001880 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001881 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001882 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001883 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001884 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001885 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001886 }
locke-lunargd556cc32019-09-17 01:21:23 -06001887 }
1888}
1889
1890void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1891 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001892 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001893}
1894
1895void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1896 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001897 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001898}
1899
1900void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1901 const VkImageMemoryRequirementsInfo2 *pInfo,
1902 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001903 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001904}
1905
locke-lunargd556cc32019-09-17 01:21:23 -06001906void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1907 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1908 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001909 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001910 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001911}
1912
1913void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001914 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1915 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001916 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001917 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001918}
1919
1920void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001921 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1922 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001923 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001924 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001925}
1926
1927void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1928 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001929 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001930}
1931
1932void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1933 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001934 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001935}
1936
1937void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1938 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001939 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001940}
1941
1942void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1943 const VkAllocationCallbacks *pAllocator) {
1944 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001945 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001946 // Any bound cmd buffers are now invalid
1947 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001948 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1949 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1950 custom_border_color_sampler_count--;
1951 }
locke-lunargd556cc32019-09-17 01:21:23 -06001952 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001953 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001954}
1955
1956void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1957 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001958 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001959}
1960
1961void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1962 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001963 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001964}
1965
locke-lunargd556cc32019-09-17 01:21:23 -06001966void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1967 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001968 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1969 if (pool) {
1970 pool->Free(commandBufferCount, pCommandBuffers);
1971 }
locke-lunargd556cc32019-09-17 01:21:23 -06001972}
1973
1974void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1975 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1976 VkResult result) {
1977 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001978 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001979 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001980}
1981
1982void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1983 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1984 VkResult result) {
1985 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001986
1987 uint32_t index_count = 0, n_perf_pass = 0;
1988 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001989 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001990 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001991 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001992
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001993 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001994 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1995 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1996 switch (counter.scope) {
1997 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001998 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001999 break;
2000 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002001 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002002 break;
2003 default:
2004 break;
2005 }
2006 }
2007
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002008 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002009 }
2010
Jeremy Gebben082a9832021-10-28 13:40:11 -06002011 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 -06002012
locke-lunargd556cc32019-09-17 01:21:23 -06002013}
2014
2015void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2016 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002017 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002018}
2019
2020void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2021 VkCommandPoolResetFlags flags, VkResult result) {
2022 if (VK_SUCCESS != result) return;
2023 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002024 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2025 if (pool) {
2026 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002027 }
2028}
2029
2030void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2031 VkResult result) {
2032 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002033 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002034 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002035 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002036 }
2037 }
2038}
2039
locke-lunargd556cc32019-09-17 01:21:23 -06002040void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2041 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002042 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002043}
2044
2045void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2046 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002047 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002048}
2049
2050void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2051 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2052 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002053 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002054}
2055
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002056std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2057 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2058 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2059 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2060}
2061
locke-lunargd556cc32019-09-17 01:21:23 -06002062bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2063 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2064 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002065 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002066 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002067 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2068 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2069 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2070 cgpl_state->pipe_state.reserve(count);
2071 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002072 const auto &create_info = pCreateInfos[i];
2073 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2074 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2075
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002076 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002077 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002078 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002079 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2080 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
Nathaniel Cesariof8500102022-04-05 13:47:44 -06002081 } else {
2082 const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
2083 const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
2084 if (!is_graphics_lib && !has_link_info) {
2085 skip = true;
2086 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002087 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002088 cgpl_state->pipe_state.push_back(
2089 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002090 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002091 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002092}
2093
2094void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2095 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2096 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2097 VkResult result, void *cgpl_state_data) {
2098 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2099 // This API may create pipelines regardless of the return value
2100 for (uint32_t i = 0; i < count; i++) {
2101 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002102 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002103 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002104 }
2105 }
2106 cgpl_state->pipe_state.clear();
2107}
2108
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002109std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2110 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2111 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2112}
2113
locke-lunargd556cc32019-09-17 01:21:23 -06002114bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2115 const VkComputePipelineCreateInfo *pCreateInfos,
2116 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002117 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002118 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2119 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2120 ccpl_state->pipe_state.reserve(count);
2121 for (uint32_t i = 0; i < count; i++) {
2122 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002123 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002124 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002125 }
2126 return false;
2127}
2128
2129void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2130 const VkComputePipelineCreateInfo *pCreateInfos,
2131 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2132 VkResult result, void *ccpl_state_data) {
2133 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2134
2135 // This API may create pipelines regardless of the return value
2136 for (uint32_t i = 0; i < count; i++) {
2137 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002138 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002139 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002140 }
2141 }
2142 ccpl_state->pipe_state.clear();
2143}
2144
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002145std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2146 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2147 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2148}
2149
locke-lunargd556cc32019-09-17 01:21:23 -06002150bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2151 uint32_t count,
2152 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2153 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002154 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002155 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2156 crtpl_state->pipe_state.reserve(count);
2157 for (uint32_t i = 0; i < count; i++) {
2158 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002159 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002160 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002161 }
2162 return false;
2163}
2164
2165void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2166 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2167 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2168 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2169 // This API may create pipelines regardless of the return value
2170 for (uint32_t i = 0; i < count; i++) {
2171 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002172 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002173 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002174 }
2175 }
2176 crtpl_state->pipe_state.clear();
2177}
2178
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002179std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2180 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2181 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2182}
2183
sourav parmarcd5fb182020-07-17 12:58:44 -07002184bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2185 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002186 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2187 const VkAllocationCallbacks *pAllocator,
2188 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002189 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002190 crtpl_state->pipe_state.reserve(count);
2191 for (uint32_t i = 0; i < count; i++) {
2192 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002193 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002194 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002195 }
2196 return false;
2197}
2198
sourav parmarcd5fb182020-07-17 12:58:44 -07002199void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2200 VkPipelineCache pipelineCache, uint32_t count,
2201 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2202 const VkAllocationCallbacks *pAllocator,
2203 VkPipeline *pPipelines, VkResult result,
2204 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002205 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002206 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002207 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002208
2209 if (!operation_is_deferred) {
2210 for (uint32_t i = 0; i < count; i++) {
2211 if (pPipelines[i] != VK_NULL_HANDLE) {
2212 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2213 Add(std::move((crtpl_state->pipe_state)[i]));
2214 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002215 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002216 } else {
2217 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2218 if (wrap_handles) {
2219 deferredOperation = layer_data->Unwrap(deferredOperation);
2220 }
2221 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2222 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2223 if (find_res->first) {
2224 cleanup_fn = std::move(find_res->second);
2225 }
2226 auto &pipeline_states = crtpl_state->pipe_state;
2227 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2228 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2229 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2230 pipeline_states[i]->SetHandle(pipelines[i]);
2231 this->Add(std::move(pipeline_states[i]));
2232 }
2233 });
2234 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002235 }
2236 crtpl_state->pipe_state.clear();
2237}
2238
locke-lunargd556cc32019-09-17 01:21:23 -06002239void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2240 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2241 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002242 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002243 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2244 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002245 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002246 }
locke-lunargd556cc32019-09-17 01:21:23 -06002247}
2248
2249void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2250 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2251 const VkAllocationCallbacks *pAllocator,
2252 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2253 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002254 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002255}
2256
locke-lunargd556cc32019-09-17 01:21:23 -06002257void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2258 const VkAllocationCallbacks *pAllocator,
2259 VkPipelineLayout *pPipelineLayout, VkResult result) {
2260 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002261 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002262}
2263
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002264std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2265 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2266 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2267}
2268
locke-lunargd556cc32019-09-17 01:21:23 -06002269void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2270 const VkAllocationCallbacks *pAllocator,
2271 VkDescriptorPool *pDescriptorPool, VkResult result) {
2272 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002273 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002274}
2275
2276void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2277 VkDescriptorPoolResetFlags flags, VkResult result) {
2278 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002279 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2280 if (pool) {
2281 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002282 }
locke-lunargd556cc32019-09-17 01:21:23 -06002283}
2284
2285bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2286 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002287 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002288 // Always update common data
2289 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2290 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2291 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2292
2293 return false;
2294}
2295
2296// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2297void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2298 VkDescriptorSet *pDescriptorSets, VkResult result,
2299 void *ads_state_data) {
2300 if (VK_SUCCESS != result) return;
2301 // All the updates are contained in a single cvdescriptorset function
2302 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2303 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002304 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2305 if (pool_state) {
2306 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2307 }
locke-lunargd556cc32019-09-17 01:21:23 -06002308}
2309
2310void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2311 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002312 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2313 if (pool_state) {
2314 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002315 }
2316}
2317
2318void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2319 const VkWriteDescriptorSet *pDescriptorWrites,
2320 uint32_t descriptorCopyCount,
2321 const VkCopyDescriptorSet *pDescriptorCopies) {
2322 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2323 pDescriptorCopies);
2324}
2325
2326void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002327 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002328 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002329 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002330 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002331 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002332 }
2333}
2334
locke-lunargd556cc32019-09-17 01:21:23 -06002335void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2336 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002337 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002338 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002339
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002340 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002341}
2342
2343void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002344 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002345 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002346
2347 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002348}
2349
2350void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2351 VkResult result) {
2352 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002353 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2354 if (cb_state) {
2355 cb_state->Reset();
2356 }
locke-lunargd556cc32019-09-17 01:21:23 -06002357 }
2358}
2359
2360CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2361 // initially assume everything is static state
2362 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2363
2364 if (ds) {
2365 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002366 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002367 }
2368 }
locke-lunargd556cc32019-09-17 01:21:23 -06002369 return flags;
2370}
2371
2372// Validation cache:
2373// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002374
2375void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2376 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002377 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002378 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002379 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002380
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002381 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002382 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002383 const auto *raster_state = pipe_state->RasterizationState();
2384 bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002385 const auto *viewport_state = pipe_state->ViewportState();
2386 const auto *dynamic_state = pipe_state->DynamicState();
locke-lunargd556cc32019-09-17 01:21:23 -06002387 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002388 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002389 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002390 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002391
2392 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002393 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2394 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002395 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002396 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002397 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002398 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002399 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002400 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002401
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002402 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002403 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2404 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2405 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002406 if (!has_dynamic_viewport_count) {
2407 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002408 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002409 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2410 // should become = ~uint32_t(0) if the other interpretation is correct.
2411 }
2412 }
2413 if (!has_dynamic_scissor_count) {
2414 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002415 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002416 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2417 // should become = ~uint32_t(0) if the other interpretation is correct.
2418 }
2419 }
locke-lunargd556cc32019-09-17 01:21:23 -06002420 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002421 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002422 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002423 if (!disabled[command_buffer_state]) {
2424 cb_state->AddChild(pipe_state);
2425 }
locke-lunargd556cc32019-09-17 01:21:23 -06002426}
2427
2428void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2429 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002430 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002431 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002432 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2433 cb_state->viewportMask |= bits;
2434 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002435
2436 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2437 for (size_t i = 0; i < viewportCount; ++i) {
2438 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2439 }
locke-lunargd556cc32019-09-17 01:21:23 -06002440}
2441
2442void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2443 uint32_t exclusiveScissorCount,
2444 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002445 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002446 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002447 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2448 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002449}
2450
2451void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2452 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002453 if (disabled[command_buffer_state]) return;
2454
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002455 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002456 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002457
2458 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002459 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002460 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002461 }
2462}
2463
2464void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2465 uint32_t viewportCount,
2466 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002467 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002468 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002469 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2470 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002471}
2472
2473void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2474 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2475 const VkAllocationCallbacks *pAllocator,
2476 VkAccelerationStructureNV *pAccelerationStructure,
2477 VkResult result) {
2478 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002479 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002480}
2481
Jeff Bolz95176d02020-04-01 00:36:16 -05002482void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2483 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2484 const VkAllocationCallbacks *pAllocator,
2485 VkAccelerationStructureKHR *pAccelerationStructure,
2486 VkResult result) {
2487 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002488 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2489 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002490}
2491
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002492void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2493 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2494 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2495 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2496 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002497 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002498 if (dst_as_state != nullptr) {
2499 dst_as_state->Build(&pInfos[i]);
2500 }
2501 }
2502}
2503
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002504// helper method for device side acceleration structure builds
2505void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2506 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2507 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2508 if (dst_as_state) {
2509 dst_as_state->Build(&info);
2510 }
2511 if (disabled[command_buffer_state]) {
2512 return;
2513 }
2514 if (dst_as_state) {
2515 cb_state.AddChild(dst_as_state);
2516 }
2517 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2518 if (src_as_state) {
2519 cb_state.AddChild(src_as_state);
2520 }
2521 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2522 if (scratch_buffer) {
2523 cb_state.AddChild(scratch_buffer);
2524 }
2525
2526 for (uint32_t i = 0; i < info.geometryCount; i++) {
2527 // only one of pGeometries and ppGeometries can be non-null
2528 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2529 switch (geom.geometryType) {
2530 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2531 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2532 if (vertex_buffer) {
2533 cb_state.AddChild(vertex_buffer);
2534 }
2535 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2536 if (index_buffer) {
2537 cb_state.AddChild(index_buffer);
2538 }
2539 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2540 if (transform_buffer) {
2541 cb_state.AddChild(transform_buffer);
2542 }
2543 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2544 if (motion_data) {
2545 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2546 if (motion_buffer) {
2547 cb_state.AddChild(motion_buffer);
2548 }
2549 }
2550 } break;
2551 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2552 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2553 if (data_buffer) {
2554 cb_state.AddChild(data_buffer);
2555 }
2556 } break;
2557 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2558 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2559 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2560 // easily ensure that's true.
2561 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2562 if (data_buffer) {
2563 cb_state.AddChild(data_buffer);
2564 }
2565 } break;
2566 default:
2567 break;
2568 }
2569 }
2570}
2571
sourav parmarcd5fb182020-07-17 12:58:44 -07002572void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2573 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2574 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002575 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002576 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002577 return;
2578 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002579 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002580 for (uint32_t i = 0; i < infoCount; i++) {
2581 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002582 }
2583 cb_state->hasBuildAccelerationStructureCmd = true;
2584}
2585
2586void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2587 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2588 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2589 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002590 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2591 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002592 return;
2593 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002594 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002595 for (uint32_t i = 0; i < infoCount; i++) {
2596 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002597 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002598 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2599 if (indirect_buffer) {
2600 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002601 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002602 }
2603 }
2604 cb_state->hasBuildAccelerationStructureCmd = true;
2605}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002606
locke-lunargd556cc32019-09-17 01:21:23 -06002607void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002608 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002609 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002610 if (as_state != nullptr) {
2611 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002612 as_state->memory_requirements_checked = true;
2613 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002614 as_state->build_scratch_memory_requirements_checked = true;
2615 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002616 as_state->update_scratch_memory_requirements_checked = true;
2617 }
2618 }
2619}
2620
sourav parmarcd5fb182020-07-17 12:58:44 -07002621void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2622 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002623 if (VK_SUCCESS != result) return;
2624 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002625 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002626
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002627 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002628 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002629 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002630 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002631 if (mem_state) {
2632 as_state->SetMemBinding(mem_state, info.memoryOffset);
2633 }
locke-lunargd556cc32019-09-17 01:21:23 -06002634
2635 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002636 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002637 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002638 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2639 }
2640 }
2641 }
2642}
2643
2644void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2645 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2646 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002647 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2648 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002649 return;
2650 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002651 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002652
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002653 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002654 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002655 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002656 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002657 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002658 }
locke-lunargd556cc32019-09-17 01:21:23 -06002659 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002660 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002661 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002662 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002663 cb_state->AddChild(src_as_state);
2664 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002665 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2666 if (instance_buffer) {
2667 cb_state->AddChild(instance_buffer);
2668 }
2669 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2670 if (scratch_buffer) {
2671 cb_state->AddChild(scratch_buffer);
2672 }
2673
2674 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2675 const auto& geom = pInfo->pGeometries[i];
2676
2677 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2678 if (vertex_buffer) {
2679 cb_state->AddChild(vertex_buffer);
2680 }
2681 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2682 if (index_buffer) {
2683 cb_state->AddChild(index_buffer);
2684 }
2685 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2686 if (transform_buffer) {
2687 cb_state->AddChild(transform_buffer);
2688 }
2689
2690 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2691 if (aabb_buffer) {
2692 cb_state->AddChild(aabb_buffer);
2693 }
2694 }
2695
locke-lunargd556cc32019-09-17 01:21:23 -06002696 }
2697 cb_state->hasBuildAccelerationStructureCmd = true;
2698}
2699
2700void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2701 VkAccelerationStructureNV dst,
2702 VkAccelerationStructureNV src,
2703 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002704 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002705 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002706 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2707 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002708 if (!disabled[command_buffer_state]) {
2709 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2710 }
locke-lunargd556cc32019-09-17 01:21:23 -06002711 if (dst_as_state != nullptr && src_as_state != nullptr) {
2712 dst_as_state->built = true;
2713 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002714 }
2715 }
2716}
2717
Jeff Bolz95176d02020-04-01 00:36:16 -05002718void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2719 VkAccelerationStructureKHR accelerationStructure,
2720 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002721 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002722}
2723
Jeff Bolz95176d02020-04-01 00:36:16 -05002724void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2725 VkAccelerationStructureNV accelerationStructure,
2726 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002727 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002728}
2729
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002730void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2731 uint32_t viewportCount,
2732 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002733 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002734 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002735}
2736
locke-lunargd556cc32019-09-17 01:21:23 -06002737void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002738 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002739 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002740}
2741
2742void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2743 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002744 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002745 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002746}
2747
2748void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2749 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002750 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002751 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002752}
2753
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002754void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2755 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002756 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002757 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002758 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2759 cb_state->scissorMask |= bits;
2760 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002761}
2762
locke-lunargd556cc32019-09-17 01:21:23 -06002763void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002764 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002765 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002766}
2767
2768void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2769 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002770 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002771 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002772}
2773
2774void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2775 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002776 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002777 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002778}
2779
2780void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2781 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002782 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002783 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002784}
2785
2786void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2787 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002788 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002789 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002790}
2791
locke-lunargd556cc32019-09-17 01:21:23 -06002792// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2793void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2794 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2795 uint32_t firstSet, uint32_t setCount,
2796 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2797 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002798 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002799 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002800 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002801 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002802
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002803 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2804 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002805}
2806
locke-lunargd556cc32019-09-17 01:21:23 -06002807void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2808 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2809 uint32_t set, uint32_t descriptorWriteCount,
2810 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002811 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002812 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002813 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002814}
2815
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002816void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2817 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2818 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002819 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2820 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002821 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002822 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2823 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002824
2825 auto &push_constant_data = cb_state->push_constant_data;
2826 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2827 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002828 cb_state->push_constant_pipeline_layout_set = layout;
2829
2830 auto flags = stageFlags;
2831 uint32_t bit_shift = 0;
2832 while (flags) {
2833 if (flags & 1) {
2834 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2835 const auto it = cb_state->push_constant_data_update.find(flag);
2836
2837 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002838 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002839 }
2840 }
2841 flags = flags >> 1;
2842 ++bit_shift;
2843 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002844 }
2845}
2846
locke-lunargd556cc32019-09-17 01:21:23 -06002847void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2848 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002849 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002850
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002851 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002852 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002853 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002854 cb_state->index_buffer_binding.offset = offset;
2855 cb_state->index_buffer_binding.index_type = indexType;
2856 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002857 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002858 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002859 }
locke-lunargd556cc32019-09-17 01:21:23 -06002860}
2861
2862void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2863 uint32_t bindingCount, const VkBuffer *pBuffers,
2864 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002865 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002866 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002867
2868 uint32_t end = firstBinding + bindingCount;
2869 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2870 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2871 }
2872
2873 for (uint32_t i = 0; i < bindingCount; ++i) {
2874 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002875 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002876 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002877 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2878 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002879 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002880 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002881 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002882 }
locke-lunargd556cc32019-09-17 01:21:23 -06002883 }
2884}
2885
2886void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2887 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002888 if (disabled[command_buffer_state]) return;
2889
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002890 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002891 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002892}
2893
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002894void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2895 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002896 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002897 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002898}
2899
2900void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2901 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002902 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002903 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2904
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002905 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2906 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002907}
2908
Tony-LunarGc43525f2021-11-15 16:12:38 -07002909void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2910 const VkDependencyInfo* pDependencyInfo) {
2911 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2912 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2913
2914 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2915 cb_state->RecordBarriers(*pDependencyInfo);
2916}
2917
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002918void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2919 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002920 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002921 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002922}
2923
2924void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2925 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002926 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002927 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002928}
2929
Tony-LunarGa2662db2021-11-16 07:26:24 -07002930void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2931 VkPipelineStageFlags2 stageMask) {
2932 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2933 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2934}
2935
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002936void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2937 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2938 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2939 uint32_t bufferMemoryBarrierCount,
2940 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2941 uint32_t imageMemoryBarrierCount,
2942 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002943 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2944 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002945 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2946 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002947}
2948
2949void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2950 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002951 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002952 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002953 const auto &dep_info = pDependencyInfos[i];
2954 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2955 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2956 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002957 }
2958}
2959
Tony-LunarG1364cf52021-11-17 16:10:11 -07002960void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2961 const VkDependencyInfo *pDependencyInfos) {
2962 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2963 for (uint32_t i = 0; i < eventCount; i++) {
2964 const auto &dep_info = pDependencyInfos[i];
2965 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2966 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2967 cb_state->RecordBarriers(dep_info);
2968 }
2969}
2970
Jeremy Gebben79649152021-06-22 14:46:24 -06002971void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2972 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2973 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2974 uint32_t bufferMemoryBarrierCount,
2975 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2976 uint32_t imageMemoryBarrierCount,
2977 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002978 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002979 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2980 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2981 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002982}
2983
2984void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2985 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002986 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002987 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2988 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002989}
2990
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002991void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2992 const VkDependencyInfo *pDependencyInfo) {
2993 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2994 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2995 cb_state->RecordBarriers(*pDependencyInfo);
2996}
2997
locke-lunargd556cc32019-09-17 01:21:23 -06002998void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2999 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003000 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003001
locke-lunargd556cc32019-09-17 01:21:23 -06003002 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003003 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003004 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003005 if (!disabled[query_validation]) {
3006 cb_state->BeginQuery(query);
3007 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003008 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003009 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003010 cb_state->AddChild(pool_state);
3011 }
locke-lunargd556cc32019-09-17 01:21:23 -06003012}
3013
3014void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003015 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003016 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003017 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003018 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003019 if (!disabled[query_validation]) {
3020 cb_state->EndQuery(query_obj);
3021 }
3022 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003023 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003024 cb_state->AddChild(pool_state);
3025 }
locke-lunargd556cc32019-09-17 01:21:23 -06003026}
3027
3028void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3029 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003030 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003031 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003032
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003033 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003034 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003035
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003036 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003037 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003038 cb_state->AddChild(pool_state);
3039 }
locke-lunargd556cc32019-09-17 01:21:23 -06003040}
3041
3042void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3043 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3044 VkDeviceSize dstOffset, VkDeviceSize stride,
3045 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003046 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3047
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003048 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003049 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003050 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003051 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003052 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003053 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003054}
3055
3056void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3057 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003058 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003059 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003060}
3061
3062void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3063 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3064 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003065 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003066 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003067}
3068
Tony-LunarGde9936b2021-11-17 15:34:11 -07003069void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3070 VkQueryPool queryPool, uint32_t slot) {
3071 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3072 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3073}
3074
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003075void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3076 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3077 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3078 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003079 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003080 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003081 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003082 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003083 cb_state->AddChild(pool_state);
3084 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003085 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003086}
3087
locke-lunargd556cc32019-09-17 01:21:23 -06003088void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3089 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3090 VkResult result) {
3091 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003092
Jeremy Gebben88f58142021-06-01 10:07:52 -06003093 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003094 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003095 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003096
locke-lunargd556cc32019-09-17 01:21:23 -06003097 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003098 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003099 }
3100 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003101
Jeremy Gebben9f537102021-10-05 16:37:12 -06003102 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003103 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003104}
3105
locke-lunargd556cc32019-09-17 01:21:23 -06003106void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3107 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3108 VkResult result) {
3109 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003110 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003111}
3112
Mike Schuchardt2df08912020-12-15 16:28:09 -08003113void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003114 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3115 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003116 if (VK_SUCCESS != result) return;
3117
Jeremy Gebben082a9832021-10-28 13:40:11 -06003118 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003119}
3120
Mike Schuchardt2df08912020-12-15 16:28:09 -08003121void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003122 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3123 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003124 if (VK_SUCCESS != result) return;
3125
Jeremy Gebben082a9832021-10-28 13:40:11 -06003126 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003127}
3128
locke-lunargd556cc32019-09-17 01:21:23 -06003129void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3130 const VkRenderPassBeginInfo *pRenderPassBegin,
3131 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003132 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003133 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003134}
3135
3136void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3137 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003138 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003139 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003140 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003141}
3142
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003143void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3144 uint32_t counterBufferCount,
3145 const VkBuffer *pCounterBuffers,
3146 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003147 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003148
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003149 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003150 cb_state->transform_feedback_active = true;
3151}
3152
3153void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3154 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3155 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003156 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003157
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003158 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003159 cb_state->transform_feedback_active = false;
3160}
3161
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003162void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3163 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003164 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003165
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003166 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003167 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003168 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3169 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003170}
3171
3172void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003173 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003174
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003175 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003176 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003177 cb_state->conditional_rendering_inside_render_pass = false;
3178 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003179}
3180
amhagana448ea52021-11-02 14:09:14 -04003181void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003182 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003183 cb_state->activeRenderPass = nullptr;
3184}
3185
3186void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3187 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003188 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003189 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3190}
3191
Tony-LunarG40b33882021-12-02 12:40:11 -07003192void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3193 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3194 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3195}
3196
amhagana448ea52021-11-02 14:09:14 -04003197void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3198 RecordCmdEndRenderingRenderPassState(commandBuffer);
3199}
3200
Tony-LunarG40b33882021-12-02 12:40:11 -07003201void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3202 RecordCmdEndRenderingRenderPassState(commandBuffer);
3203}
3204
Tony-LunarG977448c2019-12-02 14:52:02 -07003205void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3206 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003207 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003208 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003209 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003210}
3211
locke-lunargd556cc32019-09-17 01:21:23 -06003212void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003213 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003214 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003215}
3216
3217void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003218 const VkSubpassBeginInfo *pSubpassBeginInfo,
3219 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003220 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003221 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003222}
3223
Tony-LunarG977448c2019-12-02 14:52:02 -07003224void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003225 const VkSubpassBeginInfo *pSubpassBeginInfo,
3226 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003227 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003228 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003229}
3230
3231void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003232 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003233 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003234}
3235
3236void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003237 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003238 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003239 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003240}
3241
Tony-LunarG977448c2019-12-02 14:52:02 -07003242void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003243 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003244 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003245 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003246}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003247
locke-lunargd556cc32019-09-17 01:21:23 -06003248void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3249 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003250 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003251
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003252 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003253}
3254
3255void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3256 VkFlags flags, void **ppData, VkResult result) {
3257 if (VK_SUCCESS != result) return;
3258 RecordMappedMemory(mem, offset, size, ppData);
3259}
3260
3261void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003262 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003263 if (mem_info) {
3264 mem_info->mapped_range = MemRange();
3265 mem_info->p_driver_data = nullptr;
3266 }
3267}
3268
3269void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003270 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003271 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003272 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3273 // See: VUID-vkGetImageSubresourceLayout-image-01895
3274 image_state->fragment_encoder =
3275 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003276 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003277 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003278 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003279 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003280 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003281
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003282 if (!swapchain_image.fake_base_address) {
3283 auto size = image_state->fragment_encoder->TotalSize();
3284 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003285 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003286 // All images bound to this swapchain and index are aliases
3287 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003288 }
3289 } else {
3290 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003291 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003292 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003293 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003294 }
locke-lunargd556cc32019-09-17 01:21:23 -06003295 }
locke-lunargd556cc32019-09-17 01:21:23 -06003296 }
3297}
3298
3299void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3300 VkDeviceSize memoryOffset, VkResult result) {
3301 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003302 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003303 bind_info.image = image;
3304 bind_info.memory = mem;
3305 bind_info.memoryOffset = memoryOffset;
3306 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003307}
3308
3309void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003310 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003311 if (VK_SUCCESS != result) return;
3312 for (uint32_t i = 0; i < bindInfoCount; i++) {
3313 UpdateBindImageMemoryState(pBindInfos[i]);
3314 }
3315}
3316
3317void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003318 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003319 if (VK_SUCCESS != result) return;
3320 for (uint32_t i = 0; i < bindInfoCount; i++) {
3321 UpdateBindImageMemoryState(pBindInfos[i]);
3322 }
3323}
3324
3325void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003326 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003327 if (event_state) {
3328 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3329 }
locke-lunargd556cc32019-09-17 01:21:23 -06003330}
3331
3332void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3333 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3334 VkResult result) {
3335 if (VK_SUCCESS != result) return;
3336 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3337 pImportSemaphoreFdInfo->flags);
3338}
3339
3340void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003341 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003342 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003343 if (semaphore_state) {
3344 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003345 }
3346}
3347
3348#ifdef VK_USE_PLATFORM_WIN32_KHR
3349void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3350 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3351 if (VK_SUCCESS != result) return;
3352 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3353 pImportSemaphoreWin32HandleInfo->flags);
3354}
3355
3356void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3357 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3358 HANDLE *pHandle, VkResult result) {
3359 if (VK_SUCCESS != result) return;
3360 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3361}
3362
3363void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3364 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3365 if (VK_SUCCESS != result) return;
3366 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3367 pImportFenceWin32HandleInfo->flags);
3368}
3369
3370void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3371 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3372 HANDLE *pHandle, VkResult result) {
3373 if (VK_SUCCESS != result) return;
3374 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3375}
3376#endif
3377
3378void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3379 VkResult result) {
3380 if (VK_SUCCESS != result) return;
3381 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3382}
3383
Mike Schuchardt2df08912020-12-15 16:28:09 -08003384void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3385 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003386 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003387
3388 if (fence_node) {
3389 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003390 }
3391}
3392
3393void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3394 VkResult result) {
3395 if (VK_SUCCESS != result) return;
3396 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3397}
3398
Mike Schuchardt2df08912020-12-15 16:28:09 -08003399void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003400 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003401 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003402 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003403 }
3404}
3405
3406void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3407 VkResult result) {
3408 if (VK_SUCCESS != result) return;
3409 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3410}
3411
3412void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3413 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3414 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003415 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003416}
3417
3418void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003419 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003420 SWAPCHAIN_NODE *old_swapchain_state) {
3421 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003422 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003423 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003424 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003425 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3426 surface_state->AddParent(swapchain.get());
3427 surface_state->swapchain = swapchain.get();
3428 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003429 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003430 } else {
3431 surface_state->swapchain = nullptr;
3432 }
3433 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003434 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003435 if (old_swapchain_state) {
3436 old_swapchain_state->retired = true;
3437 }
3438 return;
3439}
3440
3441void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3442 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3443 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003444 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003445 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003446 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003447}
3448
3449void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3450 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003451 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003452}
3453
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003454void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3455 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3456 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3457 VkResult result) {
3458 if (VK_SUCCESS != result) return;
3459 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003460 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003461}
3462
locke-lunargd556cc32019-09-17 01:21:23 -06003463void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003464 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003465 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003466 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3467 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3468 if (semaphore_state) {
3469 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003470 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003471 }
3472
3473 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3474 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3475 // 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
3476 // confused itself just as much.
3477 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3478 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3479 // Mark the image as having been released to the WSI
3480 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3481 if (swapchain_data) {
3482 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3483 if (present_id_info) {
3484 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3485 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3486 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003487 }
3488 }
locke-lunargd556cc32019-09-17 01:21:23 -06003489 }
locke-lunargd556cc32019-09-17 01:21:23 -06003490}
3491
3492void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3493 const VkSwapchainCreateInfoKHR *pCreateInfos,
3494 const VkAllocationCallbacks *pAllocator,
3495 VkSwapchainKHR *pSwapchains, VkResult result) {
3496 if (pCreateInfos) {
3497 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003498 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003499 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003500 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3501 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003502 }
3503 }
3504}
3505
3506void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3507 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003508 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003509 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003510 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3511 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003512 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003513 }
3514
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003515 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003516 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003517 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3518 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003519 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003520 }
3521
3522 // Mark the image as acquired.
3523 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3524 if (swapchain_data) {
3525 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003526 }
3527}
3528
3529void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3530 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3531 VkResult result) {
3532 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3533 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3534}
3535
3536void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3537 uint32_t *pImageIndex, VkResult result) {
3538 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3539 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3540 pAcquireInfo->fence, pImageIndex);
3541}
3542
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003543std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3544 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3545}
3546
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003547void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3548 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3549 VkResult result) {
3550 if (result != VK_SUCCESS) {
3551 return;
3552 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003553 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003554 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003555 // this can fail if the allocator fails
3556 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3557 if (result != VK_SUCCESS) {
3558 return;
3559 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003560 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003561 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3562 if (result != VK_SUCCESS) {
3563 return;
3564 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003565
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003566 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003567 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003568 }
3569}
3570
3571// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003572static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003573 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003574}
3575
3576void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3577 uint32_t *pQueueFamilyPropertyCount,
3578 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003579 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3580 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003581 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003582}
3583
3584void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003585 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003586 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3587 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003588 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003589}
3590
3591void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003592 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003593 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3594 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003595 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003596}
3597void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3598 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003599 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003600}
3601
Jeremy Gebben082a9832021-10-28 13:40:11 -06003602void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003603
3604void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3605 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3606 const VkAllocationCallbacks *pAllocator,
3607 VkSurfaceKHR *pSurface, VkResult result) {
3608 if (VK_SUCCESS != result) return;
3609 RecordVulkanSurface(pSurface);
3610}
3611
3612#ifdef VK_USE_PLATFORM_ANDROID_KHR
3613void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3614 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3615 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3616 VkResult result) {
3617 if (VK_SUCCESS != result) return;
3618 RecordVulkanSurface(pSurface);
3619}
3620#endif // VK_USE_PLATFORM_ANDROID_KHR
3621
3622#ifdef VK_USE_PLATFORM_IOS_MVK
3623void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3624 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3625 VkResult result) {
3626 if (VK_SUCCESS != result) return;
3627 RecordVulkanSurface(pSurface);
3628}
3629#endif // VK_USE_PLATFORM_IOS_MVK
3630
3631#ifdef VK_USE_PLATFORM_MACOS_MVK
3632void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3633 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3634 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3635 VkResult result) {
3636 if (VK_SUCCESS != result) return;
3637 RecordVulkanSurface(pSurface);
3638}
3639#endif // VK_USE_PLATFORM_MACOS_MVK
3640
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003641#ifdef VK_USE_PLATFORM_METAL_EXT
3642void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3643 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3644 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3645 VkResult result) {
3646 if (VK_SUCCESS != result) return;
3647 RecordVulkanSurface(pSurface);
3648}
3649#endif // VK_USE_PLATFORM_METAL_EXT
3650
locke-lunargd556cc32019-09-17 01:21:23 -06003651#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3652void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3653 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3654 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3655 VkResult result) {
3656 if (VK_SUCCESS != result) return;
3657 RecordVulkanSurface(pSurface);
3658}
3659#endif // VK_USE_PLATFORM_WAYLAND_KHR
3660
3661#ifdef VK_USE_PLATFORM_WIN32_KHR
3662void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3663 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3664 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3665 VkResult result) {
3666 if (VK_SUCCESS != result) return;
3667 RecordVulkanSurface(pSurface);
3668}
3669#endif // VK_USE_PLATFORM_WIN32_KHR
3670
3671#ifdef VK_USE_PLATFORM_XCB_KHR
3672void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3673 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3674 VkResult result) {
3675 if (VK_SUCCESS != result) return;
3676 RecordVulkanSurface(pSurface);
3677}
3678#endif // VK_USE_PLATFORM_XCB_KHR
3679
3680#ifdef VK_USE_PLATFORM_XLIB_KHR
3681void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3682 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3683 VkResult result) {
3684 if (VK_SUCCESS != result) return;
3685 RecordVulkanSurface(pSurface);
3686}
3687#endif // VK_USE_PLATFORM_XLIB_KHR
3688
Niklas Haas8b84af12020-04-19 22:20:11 +02003689void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3690 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3691 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3692 VkResult result) {
3693 if (VK_SUCCESS != result) return;
3694 RecordVulkanSurface(pSurface);
3695}
3696
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003697void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3698 VkSurfaceKHR surface,
3699 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3700 VkResult result) {
3701 if (VK_SUCCESS != result) return;
3702 auto surface_state = Get<SURFACE_STATE>(surface);
3703 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3704}
3705
3706void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3707 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3708 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3709 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003710
3711 if (pSurfaceInfo->surface) {
3712 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3713 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3714 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3715 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3716 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3717 assert(pd_state);
3718 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3719 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003720}
3721
3722void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3723 VkSurfaceKHR surface,
3724 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3725 VkResult result) {
3726 auto surface_state = Get<SURFACE_STATE>(surface);
3727 VkSurfaceCapabilitiesKHR caps{
3728 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3729 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3730 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3731 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3732 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3733 };
3734 surface_state->SetCapabilities(physicalDevice, caps);
3735}
3736
locke-lunargd556cc32019-09-17 01:21:23 -06003737void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3738 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3739 VkBool32 *pSupported, VkResult result) {
3740 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003741 auto surface_state = Get<SURFACE_STATE>(surface);
3742 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3743}
3744
3745void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3746 VkSurfaceKHR surface,
3747 uint32_t *pPresentModeCount,
3748 VkPresentModeKHR *pPresentModes,
3749 VkResult result) {
3750 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3751
3752 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003753 if (surface) {
3754 auto surface_state = Get<SURFACE_STATE>(surface);
3755 surface_state->SetPresentModes(physicalDevice,
3756 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3757 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3758 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3759 assert(pd_state);
3760 pd_state->surfaceless_query_state.present_modes =
3761 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3762 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003763 }
3764}
3765
3766void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3767 uint32_t *pSurfaceFormatCount,
3768 VkSurfaceFormatKHR *pSurfaceFormats,
3769 VkResult result) {
3770 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3771
3772 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003773 if (surface) {
3774 auto surface_state = Get<SURFACE_STATE>(surface);
3775 surface_state->SetFormats(physicalDevice,
3776 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3777 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3778 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3779 assert(pd_state);
3780 pd_state->surfaceless_query_state.formats =
3781 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3782 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003783 }
3784}
3785
3786void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3787 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3788 uint32_t *pSurfaceFormatCount,
3789 VkSurfaceFormat2KHR *pSurfaceFormats,
3790 VkResult result) {
3791 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3792
3793 if (pSurfaceFormats) {
3794 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003795 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3796 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3797 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003798 if (pSurfaceInfo->surface) {
3799 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3800 surface_state->SetFormats(physicalDevice, std::move(fmts));
3801 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3802 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3803 assert(pd_state);
3804 pd_state->surfaceless_query_state.formats = std::move(fmts);
3805 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003806 }
locke-lunargd556cc32019-09-17 01:21:23 -06003807}
3808
locke-lunargd556cc32019-09-17 01:21:23 -06003809void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3810 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003811 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003812 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003813 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3814}
3815
3816void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003817 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003818 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003819 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3820}
3821
3822void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3823 const VkDebugUtilsLabelEXT *pLabelInfo) {
3824 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3825
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003826 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003827 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3828 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003829 cb_state->debug_label = LoggingLabel(pLabelInfo);
3830}
3831
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003832void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3833 uint32_t queueFamilyIndex,
3834 uint32_t *pCounterCount,
3835 VkPerformanceCounterKHR *pCounters) {
3836 if (NULL == pCounters) return;
3837
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003838 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3839 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003840
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003841 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3842 queue_family_counters->counters.resize(*pCounterCount);
3843 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003844
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003845 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003846}
3847
3848void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3849 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3850 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3851 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3852 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3853}
3854
3855void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3856 VkResult result) {
3857 if (result == VK_SUCCESS) performance_lock_acquired = true;
3858}
3859
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003860void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3861 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003862 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003863 cmd_buffer.second->performance_lock_released = true;
3864 }
3865}
3866
locke-lunargd556cc32019-09-17 01:21:23 -06003867void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003868 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003869 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003870 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003871}
3872
3873void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003874 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003875 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003876 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003877}
3878
Mike Schuchardt2df08912020-12-15 16:28:09 -08003879void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3880 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003881 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003882}
3883
Mike Schuchardt2df08912020-12-15 16:28:09 -08003884void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3885 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3886 const VkAllocationCallbacks *pAllocator,
3887 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3888 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003889 if (VK_SUCCESS != result) return;
3890 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3891}
3892
3893void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003894 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3895 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003896 if (VK_SUCCESS != result) return;
3897 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3898}
3899
3900void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003901 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003902 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003903 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3904 assert(template_state);
3905 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003906 // TODO: Record template push descriptor updates
3907 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003908 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003909 }
3910 }
3911}
3912
3913void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3914 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3915 const void *pData) {
3916 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3917}
3918
3919void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003920 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003921 const void *pData) {
3922 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3923}
3924
Mike Schuchardt2df08912020-12-15 16:28:09 -08003925void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3926 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3927 VkPipelineLayout layout, uint32_t set,
3928 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003929 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003930
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003931 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003932 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003933 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003934 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003935 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003936 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003937 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003938 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003939 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003940 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003941 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3942 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003943 }
3944}
3945
3946void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3947 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003948 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003949 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003950 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003951 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003952 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003953 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003954 }
3955}
3956
3957void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3958 uint32_t *pPropertyCount,
3959 VkDisplayPlanePropertiesKHR *pProperties,
3960 VkResult result) {
3961 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3962 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3963}
3964
3965void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3966 uint32_t *pPropertyCount,
3967 VkDisplayPlaneProperties2KHR *pProperties,
3968 VkResult result) {
3969 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3970 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3971}
3972
3973void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3974 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3975 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003976 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003977 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003978 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003979}
3980
3981void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3982 uint32_t query, uint32_t index) {
3983 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003984 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003985 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003986 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003987}
3988
3989void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3990 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003991 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003992
3993 if (create_info->format != VK_FORMAT_UNDEFINED) {
3994 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003995 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003996 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3997 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003998 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003999
Jeremy Gebben082a9832021-10-28 13:40:11 -06004000 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06004001}
4002
4003void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4004 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4005 const VkAllocationCallbacks *pAllocator,
4006 VkSamplerYcbcrConversion *pYcbcrConversion,
4007 VkResult result) {
4008 if (VK_SUCCESS != result) return;
4009 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4010}
4011
4012void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4013 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4014 const VkAllocationCallbacks *pAllocator,
4015 VkSamplerYcbcrConversion *pYcbcrConversion,
4016 VkResult result) {
4017 if (VK_SUCCESS != result) return;
4018 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4019}
4020
4021void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4022 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004023 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004024}
4025
4026void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4027 VkSamplerYcbcrConversion ycbcrConversion,
4028 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004029 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004030}
4031
Tony-LunarG977448c2019-12-02 14:52:02 -07004032void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4033 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004034 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004035 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004036
4037 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004038 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004039 if (!query_pool_state) return;
4040
4041 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004042 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4043 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004044 auto query_index = firstQuery + i;
4045 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004046 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004047 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004048 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004049 }
4050 }
locke-lunargd556cc32019-09-17 01:21:23 -06004051 }
4052}
4053
Tony-LunarG977448c2019-12-02 14:52:02 -07004054void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4055 uint32_t queryCount) {
4056 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4057}
4058
4059void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4060 uint32_t queryCount) {
4061 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4062}
4063
locke-lunargd556cc32019-09-17 01:21:23 -06004064void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004065 const UPDATE_TEMPLATE_STATE *template_state,
4066 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004067 // Translate the templated update into a normal update for validation...
4068 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4069 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4070 decoded_update.desc_writes.data(), 0, NULL);
4071}
4072
4073// Update the common AllocateDescriptorSetsData
4074void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004075 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004076 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004077 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004078 if (layout) {
4079 ds_data->layout_nodes[i] = layout;
4080 // Count total descriptors required per type
4081 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4082 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004083 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4084 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004085 }
4086 }
4087 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4088 }
4089}
4090
locke-lunargd556cc32019-09-17 01:21:23 -06004091void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4092 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004093 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004094 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004095}
4096
Tony-LunarG745150c2021-07-02 15:07:31 -06004097void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4098 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4099 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004100 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004101 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004102}
4103
locke-lunargd556cc32019-09-17 01:21:23 -06004104void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4105 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4106 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004107 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004108 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004109}
4110
Tony-LunarG745150c2021-07-02 15:07:31 -06004111void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4112 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4113 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4114 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004115 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004116 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004117}
4118
locke-lunargd556cc32019-09-17 01:21:23 -06004119void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4120 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004121 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004122 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004123 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004124 if (!disabled[command_buffer_state]) {
4125 cb_state->AddChild(buffer_state);
4126 }
locke-lunargd556cc32019-09-17 01:21:23 -06004127}
4128
4129void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4130 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004131 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004132 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004133 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004134 if (!disabled[command_buffer_state]) {
4135 cb_state->AddChild(buffer_state);
4136 }
locke-lunargd556cc32019-09-17 01:21:23 -06004137}
4138
4139void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004140 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004141 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004142}
4143
4144void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4145 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004146 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004147 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004148 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004149 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004150 cb_state->AddChild(buffer_state);
4151 }
locke-lunargd556cc32019-09-17 01:21:23 -06004152}
4153
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004154void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4155 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004156 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004157 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4158}
4159
4160void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4161 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004162 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004163 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4164}
4165
Tony-LunarG977448c2019-12-02 14:52:02 -07004166void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4167 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004168 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004169 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004170 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004171 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004172 auto buffer_state = Get<BUFFER_STATE>(buffer);
4173 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004174 cb_state->AddChild(buffer_state);
4175 cb_state->AddChild(count_buffer_state);
4176 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004177}
4178
locke-lunargd556cc32019-09-17 01:21:23 -06004179void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4180 VkDeviceSize offset, VkBuffer countBuffer,
4181 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4182 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004183 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004184 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004185}
4186
4187void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4188 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4189 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004190 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004191 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004192}
4193
4194void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4195 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004196 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004197 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004198 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004199 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004200 auto buffer_state = Get<BUFFER_STATE>(buffer);
4201 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004202 cb_state->AddChild(buffer_state);
4203 cb_state->AddChild(count_buffer_state);
4204 }
locke-lunargd556cc32019-09-17 01:21:23 -06004205}
4206
4207void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4208 VkDeviceSize offset, VkBuffer countBuffer,
4209 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4210 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004211 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004212 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004213}
4214
4215void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4216 VkDeviceSize offset, VkBuffer countBuffer,
4217 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4218 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004219 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004220 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004221}
4222
4223void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4224 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004225 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004226 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004227}
4228
4229void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4230 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004231 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004232 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004233 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004234 if (!disabled[command_buffer_state] && buffer_state) {
4235 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004236 }
4237}
4238
4239void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4240 VkDeviceSize offset, VkBuffer countBuffer,
4241 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4242 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004243 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004244 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004245 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004246 auto buffer_state = Get<BUFFER_STATE>(buffer);
4247 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004248 if (buffer_state) {
4249 cb_state->AddChild(buffer_state);
4250 }
4251 if (count_buffer_state) {
4252 cb_state->AddChild(count_buffer_state);
4253 }
locke-lunargd556cc32019-09-17 01:21:23 -06004254 }
4255}
4256
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004257void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4258 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4259 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4260 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4261 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4262 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4263 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004264 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004265 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004266 cb_state->hasTraceRaysCmd = true;
4267}
4268
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004269void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4270 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4271 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4272 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4273 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4274 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004275 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004276 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004277 cb_state->hasTraceRaysCmd = true;
4278}
4279
4280void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4281 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4282 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4283 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4284 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4285 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004286 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004287 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004288 cb_state->hasTraceRaysCmd = true;
4289}
4290
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004291std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4292 uint32_t unique_shader_id) const {
4293 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4294 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4295 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, spirv_environment, unique_shader_id)
4296 : std::make_shared<SHADER_MODULE_STATE>();
4297}
4298
4299std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
4300 uint32_t unique_shader_id,
4301 VkShaderModule handle) const {
4302 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
4303 bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
4304 return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
4305 : std::make_shared<SHADER_MODULE_STATE>();
4306}
4307
locke-lunargd556cc32019-09-17 01:21:23 -06004308void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4309 const VkAllocationCallbacks *pAllocator,
4310 VkShaderModule *pShaderModule, VkResult result,
4311 void *csm_state_data) {
4312 if (VK_SUCCESS != result) return;
4313 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4314
Nathaniel Cesarioee041d82022-02-15 16:32:03 -07004315 Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
locke-lunargd556cc32019-09-17 01:21:23 -06004316}
4317
John Zulauf22b0fbe2019-10-15 06:26:16 -06004318void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4319 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4320 VkResult result) {
4321 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004322 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004323
4324 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4325
4326 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004327 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004328 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004329 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004330
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004331 auto format_features = GetImageFormatFeatures(
4332 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4333 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004334
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004335 auto image_state =
4336 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004337 if (!swapchain_image.fake_base_address) {
4338 auto size = image_state->fragment_encoder->TotalSize();
4339 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004340 }
4341
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004342 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004343 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004344 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004345 }
4346 }
4347
4348 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004349 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4350 }
4351}
sourav parmar35e7a002020-06-09 17:58:44 -07004352
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004353void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4354 const VkCopyAccelerationStructureInfoKHR *pInfo,
4355 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004356 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4357 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004358 if (dst_as_state != nullptr && src_as_state != nullptr) {
4359 dst_as_state->built = true;
4360 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4361 }
4362}
4363
sourav parmar35e7a002020-06-09 17:58:44 -07004364void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4365 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004366 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004367 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004368 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004369 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4370 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004371 if (dst_as_state != nullptr && src_as_state != nullptr) {
4372 dst_as_state->built = true;
4373 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004374 if (!disabled[command_buffer_state]) {
4375 cb_state->AddChild(dst_as_state);
4376 cb_state->AddChild(src_as_state);
4377 }
sourav parmar35e7a002020-06-09 17:58:44 -07004378 }
4379 }
4380}
Piers Daniell39842ee2020-07-10 16:42:33 -06004381
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004382void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4383 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4384 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4385 if (cb_state) {
4386 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4387 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4388 if (!disabled[command_buffer_state]) {
4389 cb_state->AddChild(src_as_state);
4390 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004391 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4392 if (dst_buffer) {
4393 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004394 }
4395 }
4396}
4397
4398void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4399 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4400 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4401 if (cb_state) {
4402 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4403 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004404 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4405 if (buffer_state) {
4406 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004407 }
4408 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4409 cb_state->AddChild(dst_as_state);
4410 }
4411 }
4412}
4413
Piers Daniell39842ee2020-07-10 16:42:33 -06004414void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004415 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004416 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004417}
4418
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004419void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4420 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4421 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4422}
4423
Piers Daniell39842ee2020-07-10 16:42:33 -06004424void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004425 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004426 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004427}
4428
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004429void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4430 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4431 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4432}
4433
Piers Daniell39842ee2020-07-10 16:42:33 -06004434void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4435 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004436 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004437 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004438 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004439}
4440
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004441void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4442 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004443 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004444 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4445 cb_state->primitiveTopology = primitiveTopology;
4446}
4447
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004448void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4449 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004450 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4451 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004452 uint32_t bits = (1u << viewportCount) - 1u;
4453 cb_state->viewportWithCountMask |= bits;
4454 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004455 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004456 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004457
4458 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4459 for (size_t i = 0; i < viewportCount; ++i) {
4460 cb_state->dynamicViewports[i] = pViewports[i];
4461 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004462}
4463
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004464void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4465 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004466 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004467}
4468
4469void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004470 const VkViewport *pViewports) {
4471 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004472}
4473
4474void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4475 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004476 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004477 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004478 uint32_t bits = (1u << scissorCount) - 1u;
4479 cb_state->scissorWithCountMask |= bits;
4480 cb_state->trashedScissorMask &= ~bits;
4481 cb_state->scissorWithCountCount = scissorCount;
4482 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004483}
4484
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004485void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4486 const VkRect2D *pScissors) {
4487 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4488}
4489
4490void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4491 const VkRect2D *pScissors) {
4492 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4493}
4494
4495void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4496 uint32_t bindingCount, const VkBuffer *pBuffers,
4497 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4498 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004499 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004500 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004501
4502 uint32_t end = firstBinding + bindingCount;
4503 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4504 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4505 }
4506
4507 for (uint32_t i = 0; i < bindingCount; ++i) {
4508 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004509 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004510 vertex_buffer_binding.offset = pOffsets[i];
4511 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4512 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4513 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004514 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004515 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004516 }
4517 }
4518}
4519
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004520void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4521 uint32_t bindingCount, const VkBuffer *pBuffers,
4522 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4523 const VkDeviceSize *pStrides) {
4524 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4525 CMD_BINDVERTEXBUFFERS2EXT);
4526}
4527
4528void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4529 uint32_t bindingCount, const VkBuffer *pBuffers,
4530 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4531 const VkDeviceSize *pStrides) {
4532 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4533 CMD_BINDVERTEXBUFFERS2);
4534}
4535
Piers Daniell39842ee2020-07-10 16:42:33 -06004536void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004537 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004538 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004539}
4540
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004541void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4542 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4543 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4544}
4545
Piers Daniell39842ee2020-07-10 16:42:33 -06004546void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004547 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004548 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004549}
4550
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004551void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4552 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4553 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4554}
4555
Piers Daniell39842ee2020-07-10 16:42:33 -06004556void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004557 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004558 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004559}
4560
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004561void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4562 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4563 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4564}
4565
Piers Daniell39842ee2020-07-10 16:42:33 -06004566void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4567 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004568 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004569 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004570}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004571
4572void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4573 VkBool32 depthBoundsTestEnable) {
4574 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4575 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4576}
4577
Piers Daniell39842ee2020-07-10 16:42:33 -06004578void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004579 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004580 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004581}
4582
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004583void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4584 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4585 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4586}
4587
Piers Daniell39842ee2020-07-10 16:42:33 -06004588void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4589 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4590 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004591 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004592 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004593}
locke-lunarg4189aa22020-10-21 00:23:48 -06004594
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004595void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4596 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4597 VkCompareOp compareOp) {
4598 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4599 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4600}
4601
locke-lunarg4189aa22020-10-21 00:23:48 -06004602void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4603 uint32_t discardRectangleCount,
4604 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004605 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004606 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004607}
4608
4609void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4610 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004611 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004612 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004613}
4614
4615void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4616 VkCoarseSampleOrderTypeNV sampleOrderType,
4617 uint32_t customSampleOrderCount,
4618 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004619 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004620 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004621}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004622
4623void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004624 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004625 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004626}
4627
4628void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004629 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004630 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004631}
4632
4633void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4634 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004635 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004636 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004637}
4638
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004639void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4640 VkBool32 rasterizerDiscardEnable) {
4641 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4642 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4643}
4644
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004645void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004646 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004647 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004648}
4649
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004650void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4651 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4652 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4653}
4654
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004655void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4656 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004657 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004658 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004659}
Piers Daniell924cd832021-05-18 13:48:47 -06004660
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004661void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4662 VkBool32 primitiveRestartEnable) {
4663 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4664 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4665}
4666
Piers Daniell924cd832021-05-18 13:48:47 -06004667void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4668 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4669 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4670 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004671 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004672 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4673
4674 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4675 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4676 if (pipeline_state) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07004677 const auto *dynamic_state = pipeline_state->DynamicState();
4678 if (dynamic_state) {
4679 for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
4680 if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004681 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4682 break;
4683 }
4684 }
4685 }
4686 }
4687 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004688}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004689
ziga-lunarg67b7c392022-03-26 01:45:34 +01004690void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4691 const VkBool32 *pColorWriteEnables) {
4692 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4693 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4694 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4695}
4696
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004697void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004698 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004699 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004700 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004701 // address is used for GPU-AV and ray tracing buffer validation
4702 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004703 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004704 }
4705}
4706
4707void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4708 VkDeviceAddress address) {
4709 RecordGetBufferDeviceAddress(pInfo, address);
4710}
4711
4712void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4713 VkDeviceAddress address) {
4714 RecordGetBufferDeviceAddress(pInfo, address);
4715}
4716
4717void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4718 VkDeviceAddress address) {
4719 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004720}
4721
4722std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4723 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004724 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004725}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004726
4727std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4728 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004729 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004730 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4731}