blob: 3a573a6be1fa60fc7d512f7de560ee7d675d9337 [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Tobias Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Dave Houlton <daveh@lunarg.com>
21 * Shannon McPherson <shannon@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
28#include "vk_enum_string_helper.h"
29#include "vk_format_utils.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33#include "vk_typemap_helper.h"
34
35#include "chassis.h"
36#include "state_tracker.h"
37#include "shader_validation.h"
Jeremy Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = {
138 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
139 nullptr,
140 };
141
142 // Find the image modifier
143 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
144
145 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
146 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
147 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
148
149 // Second query to have all the modifiers filled
150 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
151
152 // Look for the image modifier in the list
153 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
154 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
155 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
156 break;
157 }
158 }
159 } else {
160 format_features =
161 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
162 }
163 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600164 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
165 nullptr};
166 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200167
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
169 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
170 nullptr};
171 format_properties_2.pNext = (void *)&drm_properties_list;
172 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
173 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
174 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
175 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
176 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200177
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600178 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
179 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
180 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
181 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200182 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200183 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600184 } else {
185 VkFormatProperties format_properties;
186 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
187 format_features =
188 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200189 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600190 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200191}
192
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700193std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
194 VkFormatFeatureFlags2KHR features) {
195 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, features);
196}
197
198std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
199 VkSwapchainKHR swapchain, uint32_t swapchain_index,
200 VkFormatFeatureFlags2KHR features) {
201 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, swapchain, swapchain_index, features);
202}
203
locke-lunargd556cc32019-09-17 01:21:23 -0600204void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
205 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
206 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200207 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700208 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600209 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600210 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600211 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200212 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
213 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
214 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600215 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700216 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600217}
218
219void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600220 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600221}
222
223void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
224 VkImageLayout imageLayout, const VkClearColorValue *pColor,
225 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600226 if (disabled[command_buffer_state]) return;
227
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700228 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600229 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600230 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600231 }
232}
233
234void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
235 VkImageLayout imageLayout,
236 const VkClearDepthStencilValue *pDepthStencil,
237 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600238 if (disabled[command_buffer_state]) return;
239
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700240 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600241 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600242 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600243 }
244}
245
246void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
247 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
248 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600252 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600253}
254
Jeff Leger178b1e52020-10-05 12:22:23 -0400255void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
256 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600257 if (disabled[command_buffer_state]) return;
258
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700259 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600260 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
261 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400262}
263
Tony-LunarGb61514a2021-11-02 12:36:51 -0600264void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
265 if (disabled[command_buffer_state]) return;
266
267 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
268 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
269 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
270}
271
locke-lunargd556cc32019-09-17 01:21:23 -0600272void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
273 VkImageLayout srcImageLayout, VkImage dstImage,
274 VkImageLayout dstImageLayout, uint32_t regionCount,
275 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600276 if (disabled[command_buffer_state]) return;
277
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700278 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600279 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600280}
281
Jeff Leger178b1e52020-10-05 12:22:23 -0400282void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
283 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600284 if (disabled[command_buffer_state]) return;
285
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700286 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600287 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
288 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400289}
290
Tony-LunarG562fc102021-11-12 13:58:35 -0700291void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
292 const VkResolveImageInfo2 *pResolveImageInfo) {
293 if (disabled[command_buffer_state]) return;
294
295 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
296 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
297 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
298}
299
locke-lunargd556cc32019-09-17 01:21:23 -0600300void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
301 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
302 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600303 if (disabled[command_buffer_state]) return;
304
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700305 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600306 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600307}
308
Jeff Leger178b1e52020-10-05 12:22:23 -0400309void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
310 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600311 if (disabled[command_buffer_state]) return;
312
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700313 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600314 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
315 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400316}
317
Tony-LunarG542ae912021-11-04 16:06:44 -0600318void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
319 if (disabled[command_buffer_state]) return;
320
321 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
322 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
323 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
324}
325
locke-lunargd556cc32019-09-17 01:21:23 -0600326void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
327 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
328 VkResult result) {
329 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600330
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600331 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600332
James Rumble2f6e7bb2021-07-13 15:21:20 +0100333 if (pCreateInfo) {
334 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700335 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700336 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100337 // address is used for GPU-AV and ray tracing buffer validation
338 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700339 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100340 }
341 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600342 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600343}
344
345void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
346 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
347 VkResult result) {
348 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600349
Jeremy Gebben9f537102021-10-05 16:37:12 -0600350 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600351
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200352 VkFormatFeatureFlags2KHR buffer_features;
353 if (has_format_feature2) {
354 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
355 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
356 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
357 buffer_features = fmt_props_3.bufferFeatures;
358 } else {
359 VkFormatProperties format_properties;
360 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
361 buffer_features = format_properties.bufferFeatures;
362 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600363
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200364 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600365}
366
367void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
368 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
369 VkResult result) {
370 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600371 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700372
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200373 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600374 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700375 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600376 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700377 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200378 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
379 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
380 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700381 }
382
locke-lunarg9939d4b2020-10-26 20:11:08 -0600383 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600384 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600385 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700386 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600387 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700388 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600389 image_format_info.type = image_state->createInfo.imageType;
390 image_format_info.format = image_state->createInfo.format;
391 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600392 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
393 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600394 image_format_info.flags = image_state->createInfo.flags;
395
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600396 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600397
398 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
399 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600400
Jeremy Gebben082a9832021-10-28 13:40:11 -0600401 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600402}
403
404void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
405 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600406 if (disabled[command_buffer_state]) return;
407
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700408 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600409 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600410}
411
Jeff Leger178b1e52020-10-05 12:22:23 -0400412void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600413 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600414 if (disabled[command_buffer_state]) return;
415
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700416 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600417 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
418 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400419}
420
Tony-LunarGef035472021-11-02 10:23:33 -0600421void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
422 if (disabled[command_buffer_state]) return;
423
424 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
425 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
426 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
427}
428
locke-lunargd556cc32019-09-17 01:21:23 -0600429void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
430 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600431 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600432}
433
434void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700435 auto buffer_state = Get<BUFFER_STATE>(buffer);
436 if (buffer_state) {
437 WriteLockGuard guard(buffer_address_lock_);
438 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
439 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600440 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600441}
442
443void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
444 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600445 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600446}
447
448void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
449 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600450 if (disabled[command_buffer_state]) return;
451
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700452 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600453 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600454}
455
456void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
457 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
458 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600459 if (disabled[command_buffer_state]) return;
460
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700461 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600462
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600463 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600464}
465
Jeff Leger178b1e52020-10-05 12:22:23 -0400466void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
467 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600468 if (disabled[command_buffer_state]) return;
469
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700470 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600471 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
472 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400473}
474
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700475void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
476 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
477 if (disabled[command_buffer_state]) return;
478
479 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
480 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
481 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
482}
483
locke-lunargd556cc32019-09-17 01:21:23 -0600484void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
485 VkImageLayout dstImageLayout, uint32_t regionCount,
486 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600487 if (disabled[command_buffer_state]) return;
488
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700489 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600490 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600491}
492
Jeff Leger178b1e52020-10-05 12:22:23 -0400493void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
494 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600495 if (disabled[command_buffer_state]) return;
496
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700497 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600498 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
499 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400500}
501
Tony Barbour845d29b2021-11-09 11:43:14 -0700502void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
503 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
504 if (disabled[command_buffer_state]) return;
505
506 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
507 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
508 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
509}
510
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700511// Gets union of all features defined by Potential Format Features
512// except, does not handle the external format case for AHB as that only can be used for sampled images
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200513VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
514 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700515
516 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200517 if (has_format_feature2) {
518 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200519 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
520 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200521 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100522
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200523 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100524
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200525 format_features |= fmt_props_3.linearTilingFeatures;
526 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100527
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200528 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
529 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
530 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
531 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
532 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100533
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200534 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
535 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
536 }
537 }
538 } else {
539 VkFormatProperties format_properties;
540 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
541 format_features |= format_properties.linearTilingFeatures;
542 format_features |= format_properties.optimalTilingFeatures;
543
544 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
545 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
546 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
547
548 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
549
550 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
551 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
552 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
553 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
554
555 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
556 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
557 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700558 }
559 }
560 }
561
562 return format_features;
563}
564
locke-lunargd556cc32019-09-17 01:21:23 -0600565void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
566 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
567 VkResult result) {
568 if (VK_SUCCESS != result) return;
569
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600570 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600571 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
572 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600573 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600574
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600575 device_state->instance_state = this;
576 // Save local link to this device's physical device state
577 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
578 // finish setup in the object representing the device
579 device_state->CreateDevice(pCreateInfo);
580}
581
582void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600583 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
584 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700585 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600586 if (features2) {
587 enabled_features_found = &(features2->features);
588 }
589 }
590
locke-lunargd556cc32019-09-17 01:21:23 -0600591 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600592 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600593 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600594 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600595 }
596
Tony-LunarG273f32f2021-09-28 08:56:30 -0600597 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
598 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600599 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600600 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600601 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600602 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
603 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600604 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600605 }
606
607 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
608 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600609 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
610 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600611 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
612 }
613
614 const auto *pipeline_creation_cache_control_features =
615 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
616 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600617 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600618 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
619 }
620
621 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
622 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600623 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600624 }
625
626 const auto *demote_to_helper_invocation_features =
627 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
628 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600629 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600630 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
631 }
632
633 const auto *terminate_invocation_features =
634 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
635 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600636 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600637 }
638
639 const auto *subgroup_size_control_features =
640 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
641 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600642 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
643 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600644 }
645
646 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
647 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600648 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600649 }
650
651 const auto *texture_compression_astchdr_features =
652 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
653 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600654 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600655 }
656
657 const auto *initialize_workgroup_memory_features =
658 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
659 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600660 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600661 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
662 }
663
664 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
665 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600666 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600667 }
668
669 const auto *shader_integer_dot_product_features =
670 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
671 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600672 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600673 }
674
675 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
676 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600677 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600678 }
679 }
680
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700681 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700682 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600683 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700684 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700685 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600686 enabled_features.core12.drawIndirectCount = VK_FALSE;
687 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
688 enabled_features.core12.descriptorIndexing = VK_FALSE;
689 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
690 enabled_features.core12.shaderOutputLayer = VK_FALSE;
691 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
692 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700693
694 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700695
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700696 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700697 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600698 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
699 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700700 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600701 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700702 }
703
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700704 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700705 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600706 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
707 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700708 }
709
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700710 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700711 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600712 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700713 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600714 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700715 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600716 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700717 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600718 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700719 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600720 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700721 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700723 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700725 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600726 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700727 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600728 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700729 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600730 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700731 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600732 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700733 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700735 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600738 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700739 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600740 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700741 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700743 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700745 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600746 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
747 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700748 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600749 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700750 }
751
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700752 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700753 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700755 }
756
757 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700758 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700761 }
762
763 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700764 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700768 }
769
770 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700771 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700772 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600773 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700774 }
775
776 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700777 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600779 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700780 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700781 }
782
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700783 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700784 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600785 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700786 }
787
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700788 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700789 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600790 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 }
792
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700793 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700794 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600795 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
796 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
797 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700798 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800799
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700800 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800801 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600802 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
803 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800804 }
805
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700806 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800807 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600808 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
809 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
810 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800811 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
812 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700813 }
814
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700815 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700816 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600817 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700818 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700819 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700821 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700822 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600823 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
824 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700825 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600826 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
827 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700828 }
829
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700830 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700831 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600832 enabled_features.core11.multiview = multiview_features->multiview;
833 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
834 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700835 }
836
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700837 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700838 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600839 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
840 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700841 }
842
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700843 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700844 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600845 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700846 }
847
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700848 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600850 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700851 }
852
853 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700854 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600856 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700857 }
858 }
859
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700860 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600861 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600862 physical_device_count = device_group_ci->physicalDeviceCount;
863 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600864 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600865 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600866 }
locke-lunargd556cc32019-09-17 01:21:23 -0600867
sfricke-samsung828e59d2021-08-22 23:20:49 -0700868 // Features from other extensions passesd in create info
869 {
870 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
871 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600872 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700873 }
locke-lunargd556cc32019-09-17 01:21:23 -0600874
sfricke-samsung828e59d2021-08-22 23:20:49 -0700875 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
876 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600877 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700878 }
locke-lunargd556cc32019-09-17 01:21:23 -0600879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
881 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600882 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700883 }
locke-lunargd556cc32019-09-17 01:21:23 -0600884
sfricke-samsung828e59d2021-08-22 23:20:49 -0700885 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
886 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600887 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700888 }
locke-lunargd556cc32019-09-17 01:21:23 -0600889
sfricke-samsung828e59d2021-08-22 23:20:49 -0700890 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
891 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600892 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700893 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700894
sfricke-samsung828e59d2021-08-22 23:20:49 -0700895 const auto *buffer_device_address_ext_features =
896 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
897 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600898 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700899 }
locke-lunargd556cc32019-09-17 01:21:23 -0600900
sfricke-samsung828e59d2021-08-22 23:20:49 -0700901 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
902 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600903 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700904 }
locke-lunargd556cc32019-09-17 01:21:23 -0600905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 const auto *compute_shader_derivatives_features =
907 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
908 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600909 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700910 }
locke-lunargd556cc32019-09-17 01:21:23 -0600911
sfricke-samsung828e59d2021-08-22 23:20:49 -0700912 const auto *fragment_shader_barycentric_features =
913 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
914 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600915 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *shader_image_footprint_features =
919 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
920 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600921 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700922 }
locke-lunargd556cc32019-09-17 01:21:23 -0600923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *fragment_shader_interlock_features =
925 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
926 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600927 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 }
locke-lunargd556cc32019-09-17 01:21:23 -0600929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *texel_buffer_alignment_features =
931 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
932 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600933 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700934 }
locke-lunargd556cc32019-09-17 01:21:23 -0600935
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 const auto *pipeline_exe_props_features =
937 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
938 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600939 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *dedicated_allocation_image_aliasing_features =
943 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
944 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600945 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500947
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
949 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600950 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700951 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100952
sfricke-samsung828e59d2021-08-22 23:20:49 -0700953 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
954 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600955 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700956 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000957
sfricke-samsung828e59d2021-08-22 23:20:49 -0700958 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
959 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600960 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700961 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800962
sfricke-samsung828e59d2021-08-22 23:20:49 -0700963 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
964 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600965 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700967
sfricke-samsung828e59d2021-08-22 23:20:49 -0700968 const auto *ray_tracing_pipeline_features =
969 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
970 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600971 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700973
sfricke-samsung828e59d2021-08-22 23:20:49 -0700974 const auto *ray_tracing_acceleration_structure_features =
975 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
976 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600977 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
981 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600982 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700983 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500984
sfricke-samsung828e59d2021-08-22 23:20:49 -0700985 const auto *fragment_density_map_features =
986 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
987 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600988 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 const auto *fragment_density_map_features2 =
992 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
993 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600994 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700995 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200996
Agarwal, Arpit78509112022-02-17 15:29:05 -0700997 const auto *fragment_density_map_offset_features =
998 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
999 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001000 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001001 }
1002
sfricke-samsung828e59d2021-08-22 23:20:49 -07001003 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1004 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001005 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001006 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001007
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1009 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001010 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001011 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001012
sfricke-samsung828e59d2021-08-22 23:20:49 -07001013 const auto *fragment_shading_rate_features =
1014 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1015 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001016 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001018
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001019 const auto *fragment_shading_rate_enums_features =
1020 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1021 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001022 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001023 }
1024
sfricke-samsung828e59d2021-08-22 23:20:49 -07001025 const auto *extended_dynamic_state_features =
1026 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1027 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001028 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001030
sfricke-samsung828e59d2021-08-22 23:20:49 -07001031 const auto *extended_dynamic_state2_features =
1032 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1033 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001034 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001035 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001036
sfricke-samsung828e59d2021-08-22 23:20:49 -07001037 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1038 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001039 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001040 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001041
sfricke-samsung828e59d2021-08-22 23:20:49 -07001042 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1043 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001044 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001045 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001046
sfricke-samsung828e59d2021-08-22 23:20:49 -07001047 const auto *shader_integer_functions2_features =
1048 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1049 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001050 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001052
sfricke-samsung828e59d2021-08-22 23:20:49 -07001053 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1054 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001055 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001056 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001057
sfricke-samsung828e59d2021-08-22 23:20:49 -07001058 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1059 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001060 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001061 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *shader_image_atomic_int64_features =
1064 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1065 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001066 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001068
sfricke-samsung828e59d2021-08-22 23:20:49 -07001069 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1070 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001071 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001072 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001073
sfricke-samsung828e59d2021-08-22 23:20:49 -07001074 const auto *conditional_rendering_features =
1075 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1076 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001077 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *workgroup_memory_explicit_layout_features =
1081 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1082 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001083 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001084 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001085
sfricke-samsung828e59d2021-08-22 23:20:49 -07001086 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1087 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001088 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001089 }
Locke Linf3873542021-04-26 11:25:10 -06001090
sfricke-samsung828e59d2021-08-22 23:20:49 -07001091 const auto *vertex_input_dynamic_state_features =
1092 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1093 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001094 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001095 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001096
sfricke-samsung828e59d2021-08-22 23:20:49 -07001097 const auto *inherited_viewport_scissor_features =
1098 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1099 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001100 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001102
sfricke-samsung828e59d2021-08-22 23:20:49 -07001103 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1104 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001105 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001106 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001107
sfricke-samsung828e59d2021-08-22 23:20:49 -07001108 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1109 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001110 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001111 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001112
sfricke-samsung828e59d2021-08-22 23:20:49 -07001113 const auto *shader_atomic_float2_features =
1114 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1115 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001116 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001117 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001118
sfricke-samsung828e59d2021-08-22 23:20:49 -07001119 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1120 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001121 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001122 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001123
sfricke-samsung828e59d2021-08-22 23:20:49 -07001124 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1125 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001126 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001128
1129 const auto *ray_tracing_motion_blur_features =
1130 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1131 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001132 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001133 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001134
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001135 const auto *primitive_topology_list_restart_features =
1136 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1137 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001138 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001139 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001140
ziga-lunarge1988962021-09-16 13:32:34 +02001141 const auto *zero_initialize_work_group_memory_features =
1142 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1143 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001144 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001145 }
1146
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001147 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1148 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001149 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001150 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001151
Tony-LunarG69604c42021-11-22 16:00:12 -07001152 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1153 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001154 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001155 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001156 }
1157
locke-lunargd556cc32019-09-17 01:21:23 -06001158 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001159 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1160 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001161
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001162 {
1163 uint32_t n_props = 0;
1164 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001165 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001166 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001167 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001168
1169 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001170 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001171 }
1172
1173 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1174 // a path to grab that information from the physical device. This
1175 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1176 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001177 has_format_feature2 =
1178 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1179 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001180 }
1181
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001182 const auto &dev_ext = device_extensions;
1183 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001184
Tony-LunarG273f32f2021-09-28 08:56:30 -06001185 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1186 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001187 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1188 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001189 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001190 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001191 } else {
1192 // VkPhysicalDeviceVulkan11Properties
1193 //
1194 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1195
1196 if (dev_ext.vk_khr_multiview) {
1197 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001198 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1199 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1200 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001201 }
1202
1203 if (dev_ext.vk_khr_maintenance3) {
1204 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001205 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1206 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1207 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001208 }
1209
1210 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001211 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001212 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1213 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1214 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001215 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001216
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001217 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1218 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1219 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1220 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001221
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001222 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001223 }
1224
1225 // VkPhysicalDeviceVulkan12Properties
1226 //
1227 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1228
1229 if (dev_ext.vk_ext_descriptor_indexing) {
1230 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001231 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1232 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001233 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001234 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001235 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001236 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001237 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001238 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001239 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001240 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001241 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001242 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001243 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001244 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1245 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1246 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001247 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001248 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001249 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001250 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001251 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001252 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001253 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001254 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001255 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001256 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001257 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001258 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001259 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001260 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001261 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001262 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001263 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001264 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001265 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001266 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001267 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001268 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001269 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001270 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001271 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001272 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001273 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001274 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001275 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1276 }
1277
1278 if (dev_ext.vk_khr_depth_stencil_resolve) {
1279 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001280 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1281 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1282 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1283 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1284 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001285 }
1286
1287 if (dev_ext.vk_khr_timeline_semaphore) {
1288 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001289 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1290 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001291 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1292 }
1293
1294 if (dev_ext.vk_ext_sampler_filter_minmax) {
1295 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001296 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1297 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001298 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001299 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001300 }
1301
1302 if (dev_ext.vk_khr_shader_float_controls) {
1303 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001304 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1305 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1306 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1307 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001308 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001309 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001310 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001311 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001312 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001313 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1314 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1315 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1316 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1317 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1318 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1319 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1320 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1321 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1322 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1323 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1324 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001325 }
locke-lunargd556cc32019-09-17 01:21:23 -06001326 }
1327
sfricke-samsung828e59d2021-08-22 23:20:49 -07001328 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001329 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1330 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1331 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1332 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1333 &phys_dev_props->inline_uniform_block_props);
1334 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1335 &phys_dev_props->vtx_attrib_divisor_props);
1336 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1337 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1338 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1339 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1340 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1341 &phys_dev_props->texel_buffer_alignment_props);
1342 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1343 &phys_dev_props->fragment_density_map_props);
1344 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1345 &phys_dev_props->fragment_density_map2_props);
1346 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001347 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001348 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1349 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1350 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1351 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1352 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1353 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1354 &phys_dev_props->fragment_shading_rate_props);
1355 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1356 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1357 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1358 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1359 &phys_dev_props->blend_operation_advanced_props);
1360 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1361 &phys_dev_props->conservative_rasterization_props);
1362 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1363 &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001364
sfricke-samsung45996a42021-09-16 13:45:27 -07001365 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001366 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001367 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1368 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001369 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1370 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001371
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001372 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001373 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1374 NULL);
1375 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001376
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001377 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1378 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001379 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001380
locke-lunargd556cc32019-09-17 01:21:23 -06001381 // Store queue family data
1382 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1383 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001384 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001385 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1386 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001387 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001388 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001389 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001390 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1391 VkQueue queue = VK_NULL_HANDLE;
1392 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1393 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1394 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1395 get_info.flags = queue_info.flags;
1396 get_info.queueFamilyIndex = queue_info.queue_family_index;
1397 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001398 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001399 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001400 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001401 }
1402 assert(queue != VK_NULL_HANDLE);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001403 Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001404 }
locke-lunargd556cc32019-09-17 01:21:23 -06001405 }
1406 }
1407}
1408
1409void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1410 if (!device) return;
1411
Jeremy Gebbend177d922021-10-28 13:42:10 -06001412 command_pool_map_.clear();
1413 assert(command_buffer_map_.empty());
1414 pipeline_map_.clear();
1415 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001416
1417 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001418 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001419 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001420 assert(descriptor_set_map_.empty());
1421 desc_template_map_.clear();
1422 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001423 // Because swapchains are associated with Surfaces, which are at instance level,
1424 // they need to be explicitly destroyed here to avoid continued references to
1425 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001426 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001427 entry.second->Destroy();
1428 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001429 swapchain_map_.clear();
1430 image_view_map_.clear();
1431 image_map_.clear();
1432 buffer_view_map_.clear();
1433 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001434 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001435 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001436}
1437
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001438void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1439 VkFence fence, VkResult result) {
1440 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001441 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001442
Jeremy Gebben57642982021-09-14 14:14:55 -06001443 uint64_t early_retire_seq = 0;
1444
1445 if (submitCount == 0) {
1446 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001447 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001448 early_retire_seq = queue_state->Submit(std::move(submission));
1449 }
locke-lunargd556cc32019-09-17 01:21:23 -06001450
1451 // Now process each individual submit
1452 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001453 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001454 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001455 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001456 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001457 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001458 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1459 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1460 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1461 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001462 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001463 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001464
locke-lunargd556cc32019-09-17 01:21:23 -06001465 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001466 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001467 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1468 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1469 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1470 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001471 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001472 }
1473
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001474 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001475 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001476
locke-lunargd556cc32019-09-17 01:21:23 -06001477 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001478 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1479 if (cb_state) {
1480 submission.AddCommandBuffer(std::move(cb_state));
1481 }
locke-lunargd556cc32019-09-17 01:21:23 -06001482 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001483 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001484 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001485 }
1486 auto submit_seq = queue_state->Submit(std::move(submission));
1487 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001488 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001489
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001490 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001491 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001492 }
1493}
1494
Tony-LunarG26fe2842021-11-16 14:07:59 -07001495void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1496 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001497 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001498 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001499 uint64_t early_retire_seq = 0;
1500 if (submitCount == 0) {
1501 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001502 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001503 early_retire_seq = queue_state->Submit(std::move(submission));
1504 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001505
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001506 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1507 CB_SUBMISSION submission;
1508 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001509 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1510 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001511 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001512 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001513 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1514 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001515 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001516 }
1517 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1518 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1519
1520 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001521 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001522 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001523 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001524 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001525 }
1526 auto submit_seq = queue_state->Submit(std::move(submission));
1527 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001528 }
locke-lunargd556cc32019-09-17 01:21:23 -06001529 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001530 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001531 }
1532}
1533
Tony-LunarG26fe2842021-11-16 14:07:59 -07001534void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1535 VkFence fence, VkResult result) {
1536 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1537}
1538
1539void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1540 VkFence fence, VkResult result) {
1541 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1542}
1543
locke-lunargd556cc32019-09-17 01:21:23 -06001544void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1545 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1546 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001547 if (VK_SUCCESS != result) {
1548 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001549 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001550 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1551 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1552 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1553
1554 layer_data::optional<DedicatedBinding> dedicated_binding;
1555
1556 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1557 if (dedicated) {
1558 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001559 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001560 assert(buffer_state);
1561 if (!buffer_state) {
1562 return;
1563 }
1564 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1565 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001566 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001567 assert(image_state);
1568 if (!image_state) {
1569 return;
1570 }
1571 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1572 }
1573 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001574 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1575 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001576 return;
1577}
1578
1579void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001580 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001581 if (mem_info) {
1582 fake_memory.Free(mem_info->fake_base_address);
1583 }
1584 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001585}
1586
1587void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1588 VkFence fence, VkResult result) {
1589 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001590 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001591
Jeremy Gebben57642982021-09-14 14:14:55 -06001592 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001593
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001594 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1595 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001596 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001597 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1598 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1599 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001600 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001601 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001602 if (buffer_state && mem_state) {
1603 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1604 }
locke-lunargd556cc32019-09-17 01:21:23 -06001605 }
1606 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001607 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1608 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1609 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001610 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001611 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001612 if (image_state && mem_state) {
1613 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1614 }
locke-lunargd556cc32019-09-17 01:21:23 -06001615 }
1616 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001617 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1618 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1619 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001620 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1621 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001622 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001623 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001624 if (image_state && mem_state) {
1625 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1626 }
locke-lunargd556cc32019-09-17 01:21:23 -06001627 }
1628 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001629 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001630 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001631 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001632 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001633 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001634 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001635 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001636 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001637 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001639 auto submit_seq = queue_state->Submit(std::move(submission));
1640 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001641 }
1642
1643 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001644 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001645 }
1646}
1647
1648void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1649 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1650 VkResult result) {
1651 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001652 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001653}
1654
Mike Schuchardt2df08912020-12-15 16:28:09 -08001655void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1656 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001657 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1658 if (semaphore_state) {
1659 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001660 }
1661}
1662
Mike Schuchardt2df08912020-12-15 16:28:09 -08001663void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001664 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001665 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001666 if (semaphore_state) {
1667 semaphore_state->RetireTimeline(pSignalInfo->value);
1668 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001669}
1670
locke-lunargd556cc32019-09-17 01:21:23 -06001671void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001672 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001673 if (mem_info) {
1674 mem_info->mapped_range.offset = offset;
1675 mem_info->mapped_range.size = size;
1676 mem_info->p_driver_data = *ppData;
1677 }
1678}
1679
locke-lunargd556cc32019-09-17 01:21:23 -06001680void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1681 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1682 if (VK_SUCCESS != result) return;
1683
1684 // When we know that all fences are complete we can clean/remove their CBs
1685 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1686 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001687 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001688 if (fence_state) {
1689 fence_state->Retire();
1690 }
locke-lunargd556cc32019-09-17 01:21:23 -06001691 }
1692 }
1693 // NOTE : Alternate case not handled here is when some fences have completed. In
1694 // this case for app to guarantee which fences completed it will have to call
1695 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1696}
1697
John Zulauff89de662020-04-13 18:57:34 -06001698void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1699 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001700 if (VK_SUCCESS != result) return;
1701
Jeremy Gebben15332642021-12-15 19:33:15 -07001702 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1703 // the application calls vkGetSemaphoreCounterValue() on each of them.
1704 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1705 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1706 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1707 if (semaphore_state) {
1708 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1709 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001710 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001711 }
1712}
1713
John Zulauff89de662020-04-13 18:57:34 -06001714void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1715 VkResult result) {
1716 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1717}
1718
1719void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1720 uint64_t timeout, VkResult result) {
1721 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1722}
1723
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001724void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1725 VkResult result) {
1726 if (VK_SUCCESS != result) return;
1727
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001728 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001729 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001730 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001731 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001732}
1733
1734void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1735 VkResult result) {
1736 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1737}
1738void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1739 VkResult result) {
1740 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1741}
1742
locke-lunargd556cc32019-09-17 01:21:23 -06001743void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1744 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001745 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001746 if (fence_state) {
1747 fence_state->Retire();
1748 }
locke-lunargd556cc32019-09-17 01:21:23 -06001749}
1750
Yilong Lice03a312022-01-02 02:08:35 -08001751void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1752 if (Get<QUEUE_STATE>(queue) == nullptr) {
1753 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1754 }
1755}
1756
1757void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1758 VkQueue *pQueue) {
1759 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1760}
1761
1762void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1763 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1764}
1765
locke-lunargd556cc32019-09-17 01:21:23 -06001766void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1767 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001768 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001769 if (queue_state) {
1770 queue_state->Retire();
1771 }
locke-lunargd556cc32019-09-17 01:21:23 -06001772}
1773
1774void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1775 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001776 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001777 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001778 }
1779}
1780
1781void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001782 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001783}
1784
1785void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1786 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001787 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001788}
1789
1790void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001791 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001792}
1793
1794void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1795 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001796 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001797}
1798
locke-lunargd556cc32019-09-17 01:21:23 -06001799void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001800 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001801 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001802 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001803 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001804 if (mem_state) {
1805 buffer_state->SetMemBinding(mem_state, memoryOffset);
1806 }
locke-lunargd556cc32019-09-17 01:21:23 -06001807 }
1808}
1809
1810void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1811 VkDeviceSize memoryOffset, VkResult result) {
1812 if (VK_SUCCESS != result) return;
1813 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1814}
1815
1816void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001817 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001818 for (uint32_t i = 0; i < bindInfoCount; i++) {
1819 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1820 }
1821}
1822
1823void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001824 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001825 for (uint32_t i = 0; i < bindInfoCount; i++) {
1826 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1827 }
1828}
1829
Spencer Fricke6c127102020-04-16 06:25:20 -07001830void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001831 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001832 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001833 buffer_state->memory_requirements_checked = true;
1834 }
1835}
1836
1837void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1838 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001839 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001840}
1841
1842void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001843 const VkBufferMemoryRequirementsInfo2 *pInfo,
1844 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001845 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001846}
1847
1848void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001849 const VkBufferMemoryRequirementsInfo2 *pInfo,
1850 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001851 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001852}
1853
Spencer Fricke6c127102020-04-16 06:25:20 -07001854void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001855 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001856 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001857 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001858 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001859 if (plane_info != nullptr) {
1860 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001861 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001862 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001863 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001864 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001865 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001866 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001867 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001868 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001869 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001870 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001871 }
locke-lunargd556cc32019-09-17 01:21:23 -06001872 }
1873}
1874
1875void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1876 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001877 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001878}
1879
1880void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1881 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001882 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001883}
1884
1885void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1886 const VkImageMemoryRequirementsInfo2 *pInfo,
1887 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001888 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001889}
1890
locke-lunargd556cc32019-09-17 01:21:23 -06001891void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1892 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1893 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001894 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001895 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001896}
1897
1898void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001899 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1900 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001901 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001902 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001903}
1904
1905void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001906 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1907 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001908 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001909 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001910}
1911
1912void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1913 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001914 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001915}
1916
1917void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1918 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001919 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001920}
1921
1922void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1923 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001924 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001925}
1926
1927void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1928 const VkAllocationCallbacks *pAllocator) {
1929 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001930 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001931 // Any bound cmd buffers are now invalid
1932 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001933 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1934 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1935 custom_border_color_sampler_count--;
1936 }
locke-lunargd556cc32019-09-17 01:21:23 -06001937 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001938 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001939}
1940
1941void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1942 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001943 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001944}
1945
1946void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1947 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001948 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001949}
1950
locke-lunargd556cc32019-09-17 01:21:23 -06001951void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1952 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001953 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1954 if (pool) {
1955 pool->Free(commandBufferCount, pCommandBuffers);
1956 }
locke-lunargd556cc32019-09-17 01:21:23 -06001957}
1958
1959void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1960 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1961 VkResult result) {
1962 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001963 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001964 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001965}
1966
1967void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1968 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1969 VkResult result) {
1970 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001971
1972 uint32_t index_count = 0, n_perf_pass = 0;
1973 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001974 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001975 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001976 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001977
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001978 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001979 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1980 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1981 switch (counter.scope) {
1982 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001983 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001984 break;
1985 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001986 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001987 break;
1988 default:
1989 break;
1990 }
1991 }
1992
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001993 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001994 }
1995
Jeremy Gebben082a9832021-10-28 13:40:11 -06001996 Add(std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb));
locke-lunargd556cc32019-09-17 01:21:23 -06001997
locke-lunargd556cc32019-09-17 01:21:23 -06001998}
1999
2000void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2001 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002002 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002003}
2004
2005void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2006 VkCommandPoolResetFlags flags, VkResult result) {
2007 if (VK_SUCCESS != result) return;
2008 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002009 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2010 if (pool) {
2011 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002012 }
2013}
2014
2015void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2016 VkResult result) {
2017 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002018 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002019 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002020 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002021 }
2022 }
2023}
2024
locke-lunargd556cc32019-09-17 01:21:23 -06002025void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2026 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002027 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002028}
2029
2030void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2031 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002032 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002033}
2034
2035void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2036 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2037 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002041std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2042 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2043 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2044 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2045}
2046
locke-lunargd556cc32019-09-17 01:21:23 -06002047bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2048 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2049 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002050 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002051 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002052 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2053 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2054 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2055 cgpl_state->pipe_state.reserve(count);
2056 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002057 const auto &create_info = pCreateInfos[i];
2058 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2059 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2060
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002061 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002062 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002063 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002064 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2065 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
ziga-lunarg08c81582022-03-08 17:33:45 +01002066 } else {
ziga-lunarg08c81582022-03-08 17:33:45 +01002067 skip = true;
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002068 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002069 cgpl_state->pipe_state.push_back(
2070 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002071 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002072 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002073}
2074
2075void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2076 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2077 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2078 VkResult result, void *cgpl_state_data) {
2079 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2080 // This API may create pipelines regardless of the return value
2081 for (uint32_t i = 0; i < count; i++) {
2082 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002083 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002084 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002085 }
2086 }
2087 cgpl_state->pipe_state.clear();
2088}
2089
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002090std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2091 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2092 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2093}
2094
locke-lunargd556cc32019-09-17 01:21:23 -06002095bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2096 const VkComputePipelineCreateInfo *pCreateInfos,
2097 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002098 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002099 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2100 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2101 ccpl_state->pipe_state.reserve(count);
2102 for (uint32_t i = 0; i < count; i++) {
2103 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002104 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002105 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002106 }
2107 return false;
2108}
2109
2110void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2111 const VkComputePipelineCreateInfo *pCreateInfos,
2112 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2113 VkResult result, void *ccpl_state_data) {
2114 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2115
2116 // This API may create pipelines regardless of the return value
2117 for (uint32_t i = 0; i < count; i++) {
2118 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002119 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002120 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002121 }
2122 }
2123 ccpl_state->pipe_state.clear();
2124}
2125
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002126std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2127 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2128 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2129}
2130
locke-lunargd556cc32019-09-17 01:21:23 -06002131bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2132 uint32_t count,
2133 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2134 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002135 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002136 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2137 crtpl_state->pipe_state.reserve(count);
2138 for (uint32_t i = 0; i < count; i++) {
2139 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002140 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002141 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002142 }
2143 return false;
2144}
2145
2146void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2147 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2148 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2149 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2150 // This API may create pipelines regardless of the return value
2151 for (uint32_t i = 0; i < count; i++) {
2152 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002153 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002154 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002155 }
2156 }
2157 crtpl_state->pipe_state.clear();
2158}
2159
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002160std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2161 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2162 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2163}
2164
sourav parmarcd5fb182020-07-17 12:58:44 -07002165bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2166 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002167 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2168 const VkAllocationCallbacks *pAllocator,
2169 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002170 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002171 crtpl_state->pipe_state.reserve(count);
2172 for (uint32_t i = 0; i < count; i++) {
2173 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002174 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002175 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002176 }
2177 return false;
2178}
2179
sourav parmarcd5fb182020-07-17 12:58:44 -07002180void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2181 VkPipelineCache pipelineCache, uint32_t count,
2182 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2183 const VkAllocationCallbacks *pAllocator,
2184 VkPipeline *pPipelines, VkResult result,
2185 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002186 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2187 // This API may create pipelines regardless of the return value
2188 for (uint32_t i = 0; i < count; i++) {
2189 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002190 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002191 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002192 }
2193 }
2194 crtpl_state->pipe_state.clear();
2195}
2196
locke-lunargd556cc32019-09-17 01:21:23 -06002197void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2198 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2199 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002200 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002201 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2202 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002203 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002204 }
locke-lunargd556cc32019-09-17 01:21:23 -06002205}
2206
2207void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2208 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2209 const VkAllocationCallbacks *pAllocator,
2210 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2211 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002212 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002213}
2214
locke-lunargd556cc32019-09-17 01:21:23 -06002215void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2216 const VkAllocationCallbacks *pAllocator,
2217 VkPipelineLayout *pPipelineLayout, VkResult result) {
2218 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002219 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002220}
2221
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002222std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2223 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2224 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2225}
2226
locke-lunargd556cc32019-09-17 01:21:23 -06002227void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2228 const VkAllocationCallbacks *pAllocator,
2229 VkDescriptorPool *pDescriptorPool, VkResult result) {
2230 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002231 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002232}
2233
2234void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2235 VkDescriptorPoolResetFlags flags, VkResult result) {
2236 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002237 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2238 if (pool) {
2239 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002240 }
locke-lunargd556cc32019-09-17 01:21:23 -06002241}
2242
2243bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2244 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002245 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002246 // Always update common data
2247 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2248 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2249 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2250
2251 return false;
2252}
2253
2254// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2255void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2256 VkDescriptorSet *pDescriptorSets, VkResult result,
2257 void *ads_state_data) {
2258 if (VK_SUCCESS != result) return;
2259 // All the updates are contained in a single cvdescriptorset function
2260 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2261 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002262 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2263 if (pool_state) {
2264 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2265 }
locke-lunargd556cc32019-09-17 01:21:23 -06002266}
2267
2268void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2269 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002270 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2271 if (pool_state) {
2272 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002273 }
2274}
2275
2276void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2277 const VkWriteDescriptorSet *pDescriptorWrites,
2278 uint32_t descriptorCopyCount,
2279 const VkCopyDescriptorSet *pDescriptorCopies) {
2280 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2281 pDescriptorCopies);
2282}
2283
2284void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002285 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002286 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002287 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002288 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002289 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002290 }
2291}
2292
locke-lunargd556cc32019-09-17 01:21:23 -06002293void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2294 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002295 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002296 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002297
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002298 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002299}
2300
2301void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002302 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002303 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002304
2305 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002306}
2307
2308void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2309 VkResult result) {
2310 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002311 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2312 if (cb_state) {
2313 cb_state->Reset();
2314 }
locke-lunargd556cc32019-09-17 01:21:23 -06002315 }
2316}
2317
2318CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2319 // initially assume everything is static state
2320 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2321
2322 if (ds) {
2323 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002324 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002325 }
2326 }
locke-lunargd556cc32019-09-17 01:21:23 -06002327 return flags;
2328}
2329
2330// Validation cache:
2331// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002332
2333void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2334 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002335 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002336 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002337 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002338
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002339 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002340 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002341 const auto &create_info = pipe_state->create_info.graphics;
2342 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2343 const auto *viewport_state = create_info.pViewportState;
2344 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002345 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002346 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002347 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002348 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002349
2350 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002351 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2352 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002353 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002354 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002355 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002356 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002357 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002358 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002359
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002360 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002361 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2362 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2363 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002364 if (!has_dynamic_viewport_count) {
2365 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002366 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002367 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2368 // should become = ~uint32_t(0) if the other interpretation is correct.
2369 }
2370 }
2371 if (!has_dynamic_scissor_count) {
2372 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002373 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002374 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2375 // should become = ~uint32_t(0) if the other interpretation is correct.
2376 }
2377 }
locke-lunargd556cc32019-09-17 01:21:23 -06002378 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002379 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002380 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002381 if (!disabled[command_buffer_state]) {
2382 cb_state->AddChild(pipe_state);
2383 }
locke-lunargd556cc32019-09-17 01:21:23 -06002384}
2385
2386void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2387 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002388 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002389 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002390 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2391 cb_state->viewportMask |= bits;
2392 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002393
2394 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2395 for (size_t i = 0; i < viewportCount; ++i) {
2396 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2397 }
locke-lunargd556cc32019-09-17 01:21:23 -06002398}
2399
2400void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2401 uint32_t exclusiveScissorCount,
2402 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002403 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002404 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002405 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2406 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002407}
2408
2409void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2410 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002411 if (disabled[command_buffer_state]) return;
2412
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002413 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002414 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002415
2416 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002417 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002418 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002419 }
2420}
2421
2422void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2423 uint32_t viewportCount,
2424 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002425 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002426 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002427 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2428 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002429}
2430
2431void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2432 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2433 const VkAllocationCallbacks *pAllocator,
2434 VkAccelerationStructureNV *pAccelerationStructure,
2435 VkResult result) {
2436 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002437 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002438}
2439
Jeff Bolz95176d02020-04-01 00:36:16 -05002440void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2441 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2442 const VkAllocationCallbacks *pAllocator,
2443 VkAccelerationStructureKHR *pAccelerationStructure,
2444 VkResult result) {
2445 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002446 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2447 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002448}
2449
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002450void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2451 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2452 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2453 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2454 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002455 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002456 if (dst_as_state != nullptr) {
2457 dst_as_state->Build(&pInfos[i]);
2458 }
2459 }
2460}
2461
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002462// helper method for device side acceleration structure builds
2463void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2464 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2465 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2466 if (dst_as_state) {
2467 dst_as_state->Build(&info);
2468 }
2469 if (disabled[command_buffer_state]) {
2470 return;
2471 }
2472 if (dst_as_state) {
2473 cb_state.AddChild(dst_as_state);
2474 }
2475 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2476 if (src_as_state) {
2477 cb_state.AddChild(src_as_state);
2478 }
2479 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2480 if (scratch_buffer) {
2481 cb_state.AddChild(scratch_buffer);
2482 }
2483
2484 for (uint32_t i = 0; i < info.geometryCount; i++) {
2485 // only one of pGeometries and ppGeometries can be non-null
2486 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2487 switch (geom.geometryType) {
2488 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2489 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2490 if (vertex_buffer) {
2491 cb_state.AddChild(vertex_buffer);
2492 }
2493 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2494 if (index_buffer) {
2495 cb_state.AddChild(index_buffer);
2496 }
2497 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2498 if (transform_buffer) {
2499 cb_state.AddChild(transform_buffer);
2500 }
2501 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2502 if (motion_data) {
2503 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2504 if (motion_buffer) {
2505 cb_state.AddChild(motion_buffer);
2506 }
2507 }
2508 } break;
2509 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2510 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2511 if (data_buffer) {
2512 cb_state.AddChild(data_buffer);
2513 }
2514 } break;
2515 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2516 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2517 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2518 // easily ensure that's true.
2519 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2520 if (data_buffer) {
2521 cb_state.AddChild(data_buffer);
2522 }
2523 } break;
2524 default:
2525 break;
2526 }
2527 }
2528}
2529
sourav parmarcd5fb182020-07-17 12:58:44 -07002530void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2531 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2532 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002533 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002534 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002535 return;
2536 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002537 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002538 for (uint32_t i = 0; i < infoCount; i++) {
2539 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002540 }
2541 cb_state->hasBuildAccelerationStructureCmd = true;
2542}
2543
2544void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2545 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2546 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2547 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002548 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2549 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002550 return;
2551 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002552 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002553 for (uint32_t i = 0; i < infoCount; i++) {
2554 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002555 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002556 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2557 if (indirect_buffer) {
2558 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002559 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002560 }
2561 }
2562 cb_state->hasBuildAccelerationStructureCmd = true;
2563}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002564
locke-lunargd556cc32019-09-17 01:21:23 -06002565void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002566 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002567 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002568 if (as_state != nullptr) {
2569 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002570 as_state->memory_requirements_checked = true;
2571 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002572 as_state->build_scratch_memory_requirements_checked = true;
2573 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002574 as_state->update_scratch_memory_requirements_checked = true;
2575 }
2576 }
2577}
2578
sourav parmarcd5fb182020-07-17 12:58:44 -07002579void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2580 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002581 if (VK_SUCCESS != result) return;
2582 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002583 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002584
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002585 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002586 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002587 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002588 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002589 if (mem_state) {
2590 as_state->SetMemBinding(mem_state, info.memoryOffset);
2591 }
locke-lunargd556cc32019-09-17 01:21:23 -06002592
2593 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002594 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002595 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002596 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2597 }
2598 }
2599 }
2600}
2601
2602void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2603 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2604 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002605 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2606 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002607 return;
2608 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002609 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002610
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002611 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002612 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002613 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002614 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002615 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002616 }
locke-lunargd556cc32019-09-17 01:21:23 -06002617 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002618 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002619 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002620 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002621 cb_state->AddChild(src_as_state);
2622 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002623 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2624 if (instance_buffer) {
2625 cb_state->AddChild(instance_buffer);
2626 }
2627 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2628 if (scratch_buffer) {
2629 cb_state->AddChild(scratch_buffer);
2630 }
2631
2632 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2633 const auto& geom = pInfo->pGeometries[i];
2634
2635 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2636 if (vertex_buffer) {
2637 cb_state->AddChild(vertex_buffer);
2638 }
2639 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2640 if (index_buffer) {
2641 cb_state->AddChild(index_buffer);
2642 }
2643 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2644 if (transform_buffer) {
2645 cb_state->AddChild(transform_buffer);
2646 }
2647
2648 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2649 if (aabb_buffer) {
2650 cb_state->AddChild(aabb_buffer);
2651 }
2652 }
2653
locke-lunargd556cc32019-09-17 01:21:23 -06002654 }
2655 cb_state->hasBuildAccelerationStructureCmd = true;
2656}
2657
2658void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2659 VkAccelerationStructureNV dst,
2660 VkAccelerationStructureNV src,
2661 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002662 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002663 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002664 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2665 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002666 if (!disabled[command_buffer_state]) {
2667 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2668 }
locke-lunargd556cc32019-09-17 01:21:23 -06002669 if (dst_as_state != nullptr && src_as_state != nullptr) {
2670 dst_as_state->built = true;
2671 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002672 }
2673 }
2674}
2675
Jeff Bolz95176d02020-04-01 00:36:16 -05002676void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2677 VkAccelerationStructureKHR accelerationStructure,
2678 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002679 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002680}
2681
Jeff Bolz95176d02020-04-01 00:36:16 -05002682void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2683 VkAccelerationStructureNV accelerationStructure,
2684 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002685 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002686}
2687
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002688void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2689 uint32_t viewportCount,
2690 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002691 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002692 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002693}
2694
locke-lunargd556cc32019-09-17 01:21:23 -06002695void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002696 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002697 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002698}
2699
2700void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2701 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002702 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002703 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002704}
2705
2706void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2707 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002708 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002709 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002710}
2711
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002712void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2713 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002714 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002715 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002716 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2717 cb_state->scissorMask |= bits;
2718 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002719}
2720
locke-lunargd556cc32019-09-17 01:21:23 -06002721void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002722 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002723 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002724}
2725
2726void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2727 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002728 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002729 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002730}
2731
2732void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2733 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002734 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002735 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002736}
2737
2738void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2739 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002740 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002741 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002742}
2743
2744void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2745 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002746 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002747 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002748}
2749
locke-lunargd556cc32019-09-17 01:21:23 -06002750// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2751void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2752 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2753 uint32_t firstSet, uint32_t setCount,
2754 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2755 const uint32_t *pDynamicOffsets) {
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->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002758 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002759 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002760
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002761 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2762 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002763}
2764
locke-lunargd556cc32019-09-17 01:21:23 -06002765void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2766 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2767 uint32_t set, uint32_t descriptorWriteCount,
2768 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002769 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002770 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002771 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002772}
2773
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002774void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2775 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2776 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002777 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2778 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002779 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002780 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2781 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002782
2783 auto &push_constant_data = cb_state->push_constant_data;
2784 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2785 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002786 cb_state->push_constant_pipeline_layout_set = layout;
2787
2788 auto flags = stageFlags;
2789 uint32_t bit_shift = 0;
2790 while (flags) {
2791 if (flags & 1) {
2792 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2793 const auto it = cb_state->push_constant_data_update.find(flag);
2794
2795 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002796 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002797 }
2798 }
2799 flags = flags >> 1;
2800 ++bit_shift;
2801 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002802 }
2803}
2804
locke-lunargd556cc32019-09-17 01:21:23 -06002805void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2806 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002807 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002808
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002809 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002810 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002811 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002812 cb_state->index_buffer_binding.offset = offset;
2813 cb_state->index_buffer_binding.index_type = indexType;
2814 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002815 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002816 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002817 }
locke-lunargd556cc32019-09-17 01:21:23 -06002818}
2819
2820void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2821 uint32_t bindingCount, const VkBuffer *pBuffers,
2822 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002823 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002824 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002825
2826 uint32_t end = firstBinding + bindingCount;
2827 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2828 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2829 }
2830
2831 for (uint32_t i = 0; i < bindingCount; ++i) {
2832 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002833 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002834 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002835 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2836 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002837 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002838 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002839 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002840 }
locke-lunargd556cc32019-09-17 01:21:23 -06002841 }
2842}
2843
2844void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2845 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002846 if (disabled[command_buffer_state]) return;
2847
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002848 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002849 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002850}
2851
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002852void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2853 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002854 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002855 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002856}
2857
2858void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2859 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002860 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002861 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2862
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002863 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2864 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002865}
2866
Tony-LunarGc43525f2021-11-15 16:12:38 -07002867void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2868 const VkDependencyInfo* pDependencyInfo) {
2869 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2870 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2871
2872 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2873 cb_state->RecordBarriers(*pDependencyInfo);
2874}
2875
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002876void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2877 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002878 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002879 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002880}
2881
2882void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2883 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002884 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002885 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002886}
2887
Tony-LunarGa2662db2021-11-16 07:26:24 -07002888void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2889 VkPipelineStageFlags2 stageMask) {
2890 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2891 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2892}
2893
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002894void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2895 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2896 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2897 uint32_t bufferMemoryBarrierCount,
2898 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2899 uint32_t imageMemoryBarrierCount,
2900 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002901 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2902 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002903 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2904 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002905}
2906
2907void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2908 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002909 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002910 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002911 const auto &dep_info = pDependencyInfos[i];
2912 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2913 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2914 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002915 }
2916}
2917
Tony-LunarG1364cf52021-11-17 16:10:11 -07002918void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2919 const VkDependencyInfo *pDependencyInfos) {
2920 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2921 for (uint32_t i = 0; i < eventCount; i++) {
2922 const auto &dep_info = pDependencyInfos[i];
2923 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2924 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2925 cb_state->RecordBarriers(dep_info);
2926 }
2927}
2928
Jeremy Gebben79649152021-06-22 14:46:24 -06002929void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2930 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2931 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2932 uint32_t bufferMemoryBarrierCount,
2933 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2934 uint32_t imageMemoryBarrierCount,
2935 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002936 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002937 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2938 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2939 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002940}
2941
2942void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2943 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002944 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002945 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2946 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002947}
2948
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002949void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2950 const VkDependencyInfo *pDependencyInfo) {
2951 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2952 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2953 cb_state->RecordBarriers(*pDependencyInfo);
2954}
2955
locke-lunargd556cc32019-09-17 01:21:23 -06002956void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2957 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002958 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002959
locke-lunargd556cc32019-09-17 01:21:23 -06002960 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002961 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002962 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002963 if (!disabled[query_validation]) {
2964 cb_state->BeginQuery(query);
2965 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002966 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002967 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002968 cb_state->AddChild(pool_state);
2969 }
locke-lunargd556cc32019-09-17 01:21:23 -06002970}
2971
2972void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002973 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002974 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002975 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002976 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002977 if (!disabled[query_validation]) {
2978 cb_state->EndQuery(query_obj);
2979 }
2980 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002981 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002982 cb_state->AddChild(pool_state);
2983 }
locke-lunargd556cc32019-09-17 01:21:23 -06002984}
2985
2986void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2987 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002988 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002989 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002990
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002991 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002992 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002993
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002994 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002995 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002996 cb_state->AddChild(pool_state);
2997 }
locke-lunargd556cc32019-09-17 01:21:23 -06002998}
2999
3000void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3001 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3002 VkDeviceSize dstOffset, VkDeviceSize stride,
3003 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003004 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3005
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003006 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003007 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003008 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003009 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003010 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003011 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003012}
3013
3014void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3015 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003016 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003017 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003018}
3019
3020void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3021 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3022 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003023 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003024 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003025}
3026
Tony-LunarGde9936b2021-11-17 15:34:11 -07003027void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3028 VkQueryPool queryPool, uint32_t slot) {
3029 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3030 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3031}
3032
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003033void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3034 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3035 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3036 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003037 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003038 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003039 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003040 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003041 cb_state->AddChild(pool_state);
3042 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003043 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003044}
3045
locke-lunargd556cc32019-09-17 01:21:23 -06003046void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3047 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3048 VkResult result) {
3049 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003050
Jeremy Gebben88f58142021-06-01 10:07:52 -06003051 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003052 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003053 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003054
locke-lunargd556cc32019-09-17 01:21:23 -06003055 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003056 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003057 }
3058 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003059
Jeremy Gebben9f537102021-10-05 16:37:12 -06003060 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003061 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003062}
3063
locke-lunargd556cc32019-09-17 01:21:23 -06003064void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3065 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3066 VkResult result) {
3067 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003068 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003069}
3070
Mike Schuchardt2df08912020-12-15 16:28:09 -08003071void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003072 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3073 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003074 if (VK_SUCCESS != result) return;
3075
Jeremy Gebben082a9832021-10-28 13:40:11 -06003076 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003077}
3078
Mike Schuchardt2df08912020-12-15 16:28:09 -08003079void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003080 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3081 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003082 if (VK_SUCCESS != result) return;
3083
Jeremy Gebben082a9832021-10-28 13:40:11 -06003084 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003085}
3086
locke-lunargd556cc32019-09-17 01:21:23 -06003087void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3088 const VkRenderPassBeginInfo *pRenderPassBegin,
3089 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003090 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003091 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003092}
3093
3094void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3095 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003096 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003097 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003098 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003099}
3100
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003101void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3102 uint32_t counterBufferCount,
3103 const VkBuffer *pCounterBuffers,
3104 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003105 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003106
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003107 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003108 cb_state->transform_feedback_active = true;
3109}
3110
3111void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3112 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3113 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003114 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003115
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003116 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003117 cb_state->transform_feedback_active = false;
3118}
3119
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003120void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3121 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003122 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003123
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003124 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003125 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003126 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3127 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003128}
3129
3130void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003131 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003132
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003133 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003134 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003135 cb_state->conditional_rendering_inside_render_pass = false;
3136 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003137}
3138
amhagana448ea52021-11-02 14:09:14 -04003139void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003140 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003141 cb_state->activeRenderPass = nullptr;
3142}
3143
3144void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3145 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003146 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003147 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3148}
3149
Tony-LunarG40b33882021-12-02 12:40:11 -07003150void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3151 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3152 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3153}
3154
amhagana448ea52021-11-02 14:09:14 -04003155void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3156 RecordCmdEndRenderingRenderPassState(commandBuffer);
3157}
3158
Tony-LunarG40b33882021-12-02 12:40:11 -07003159void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3160 RecordCmdEndRenderingRenderPassState(commandBuffer);
3161}
3162
Tony-LunarG977448c2019-12-02 14:52:02 -07003163void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3164 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003165 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003166 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003167 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003168}
3169
locke-lunargd556cc32019-09-17 01:21:23 -06003170void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003171 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003172 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003173}
3174
3175void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003176 const VkSubpassBeginInfo *pSubpassBeginInfo,
3177 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003178 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003179 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003180}
3181
Tony-LunarG977448c2019-12-02 14:52:02 -07003182void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003183 const VkSubpassBeginInfo *pSubpassBeginInfo,
3184 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003185 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003186 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003187}
3188
3189void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003190 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003191 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003192}
3193
3194void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003195 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003196 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003197 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003198}
3199
Tony-LunarG977448c2019-12-02 14:52:02 -07003200void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003201 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003202 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003203 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003204}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003205
locke-lunargd556cc32019-09-17 01:21:23 -06003206void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3207 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003208 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003209
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003210 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003211}
3212
3213void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3214 VkFlags flags, void **ppData, VkResult result) {
3215 if (VK_SUCCESS != result) return;
3216 RecordMappedMemory(mem, offset, size, ppData);
3217}
3218
3219void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003220 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003221 if (mem_info) {
3222 mem_info->mapped_range = MemRange();
3223 mem_info->p_driver_data = nullptr;
3224 }
3225}
3226
3227void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003228 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003229 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003230 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3231 // See: VUID-vkGetImageSubresourceLayout-image-01895
3232 image_state->fragment_encoder =
3233 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003234 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003235 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003236 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003237 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003238 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003239
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003240 if (!swapchain_image.fake_base_address) {
3241 auto size = image_state->fragment_encoder->TotalSize();
3242 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003243 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003244 // All images bound to this swapchain and index are aliases
3245 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003246 }
3247 } else {
3248 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003249 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003250 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003251 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003252 }
locke-lunargd556cc32019-09-17 01:21:23 -06003253 }
locke-lunargd556cc32019-09-17 01:21:23 -06003254 }
3255}
3256
3257void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3258 VkDeviceSize memoryOffset, VkResult result) {
3259 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003260 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003261 bind_info.image = image;
3262 bind_info.memory = mem;
3263 bind_info.memoryOffset = memoryOffset;
3264 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003265}
3266
3267void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003268 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003269 if (VK_SUCCESS != result) return;
3270 for (uint32_t i = 0; i < bindInfoCount; i++) {
3271 UpdateBindImageMemoryState(pBindInfos[i]);
3272 }
3273}
3274
3275void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003276 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003277 if (VK_SUCCESS != result) return;
3278 for (uint32_t i = 0; i < bindInfoCount; i++) {
3279 UpdateBindImageMemoryState(pBindInfos[i]);
3280 }
3281}
3282
3283void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003284 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003285 if (event_state) {
3286 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3287 }
locke-lunargd556cc32019-09-17 01:21:23 -06003288}
3289
3290void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3291 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3292 VkResult result) {
3293 if (VK_SUCCESS != result) return;
3294 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3295 pImportSemaphoreFdInfo->flags);
3296}
3297
3298void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003299 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003300 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003301 if (semaphore_state) {
3302 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003303 }
3304}
3305
3306#ifdef VK_USE_PLATFORM_WIN32_KHR
3307void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3308 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3309 if (VK_SUCCESS != result) return;
3310 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3311 pImportSemaphoreWin32HandleInfo->flags);
3312}
3313
3314void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3315 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3316 HANDLE *pHandle, VkResult result) {
3317 if (VK_SUCCESS != result) return;
3318 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3319}
3320
3321void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3322 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3323 if (VK_SUCCESS != result) return;
3324 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3325 pImportFenceWin32HandleInfo->flags);
3326}
3327
3328void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3329 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3330 HANDLE *pHandle, VkResult result) {
3331 if (VK_SUCCESS != result) return;
3332 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3333}
3334#endif
3335
3336void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3337 VkResult result) {
3338 if (VK_SUCCESS != result) return;
3339 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3340}
3341
Mike Schuchardt2df08912020-12-15 16:28:09 -08003342void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3343 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003344 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003345
3346 if (fence_node) {
3347 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003348 }
3349}
3350
3351void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3352 VkResult result) {
3353 if (VK_SUCCESS != result) return;
3354 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3355}
3356
Mike Schuchardt2df08912020-12-15 16:28:09 -08003357void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003358 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003359 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003360 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003361 }
3362}
3363
3364void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3365 VkResult result) {
3366 if (VK_SUCCESS != result) return;
3367 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3368}
3369
3370void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3371 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3372 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003373 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003374}
3375
3376void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003377 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003378 SWAPCHAIN_NODE *old_swapchain_state) {
3379 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003380 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003381 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003382 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003383 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3384 surface_state->AddParent(swapchain.get());
3385 surface_state->swapchain = swapchain.get();
3386 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003387 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003388 } else {
3389 surface_state->swapchain = nullptr;
3390 }
3391 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003392 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003393 if (old_swapchain_state) {
3394 old_swapchain_state->retired = true;
3395 }
3396 return;
3397}
3398
3399void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3400 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3401 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003402 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003403 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003404 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003405}
3406
3407void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3408 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003409 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003410}
3411
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003412void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3413 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3414 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3415 VkResult result) {
3416 if (VK_SUCCESS != result) return;
3417 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003418 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003419}
3420
locke-lunargd556cc32019-09-17 01:21:23 -06003421void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003422 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003423 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003424 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3425 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3426 if (semaphore_state) {
3427 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003428 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003429 }
3430
3431 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3432 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3433 // 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
3434 // confused itself just as much.
3435 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3436 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3437 // Mark the image as having been released to the WSI
3438 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3439 if (swapchain_data) {
3440 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3441 if (present_id_info) {
3442 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3443 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3444 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003445 }
3446 }
locke-lunargd556cc32019-09-17 01:21:23 -06003447 }
locke-lunargd556cc32019-09-17 01:21:23 -06003448}
3449
3450void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3451 const VkSwapchainCreateInfoKHR *pCreateInfos,
3452 const VkAllocationCallbacks *pAllocator,
3453 VkSwapchainKHR *pSwapchains, VkResult result) {
3454 if (pCreateInfos) {
3455 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003456 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003457 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003458 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3459 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003460 }
3461 }
3462}
3463
3464void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3465 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003466 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003467 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003468 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3469 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003470 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003471 }
3472
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003473 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003474 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003475 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3476 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003477 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003478 }
3479
3480 // Mark the image as acquired.
3481 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3482 if (swapchain_data) {
3483 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003484 }
3485}
3486
3487void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3488 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3489 VkResult result) {
3490 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3491 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3492}
3493
3494void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3495 uint32_t *pImageIndex, VkResult result) {
3496 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3497 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3498 pAcquireInfo->fence, pImageIndex);
3499}
3500
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003501std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3502 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3503}
3504
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003505void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3506 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3507 VkResult result) {
3508 if (result != VK_SUCCESS) {
3509 return;
3510 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003511 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003512 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003513 // this can fail if the allocator fails
3514 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3515 if (result != VK_SUCCESS) {
3516 return;
3517 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003518 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003519 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3520 if (result != VK_SUCCESS) {
3521 return;
3522 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003523
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003524 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003525 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003526 }
3527}
3528
3529// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003530static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003531 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003532}
3533
3534void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3535 uint32_t *pQueueFamilyPropertyCount,
3536 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003537 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3538 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003539 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003540}
3541
3542void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003543 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003544 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3545 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003546 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003547}
3548
3549void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003550 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003551 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3552 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003553 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003554}
3555void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3556 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003557 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003558}
3559
Jeremy Gebben082a9832021-10-28 13:40:11 -06003560void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003561
3562void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3563 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3564 const VkAllocationCallbacks *pAllocator,
3565 VkSurfaceKHR *pSurface, VkResult result) {
3566 if (VK_SUCCESS != result) return;
3567 RecordVulkanSurface(pSurface);
3568}
3569
3570#ifdef VK_USE_PLATFORM_ANDROID_KHR
3571void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3572 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3573 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3574 VkResult result) {
3575 if (VK_SUCCESS != result) return;
3576 RecordVulkanSurface(pSurface);
3577}
3578#endif // VK_USE_PLATFORM_ANDROID_KHR
3579
3580#ifdef VK_USE_PLATFORM_IOS_MVK
3581void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3582 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3583 VkResult result) {
3584 if (VK_SUCCESS != result) return;
3585 RecordVulkanSurface(pSurface);
3586}
3587#endif // VK_USE_PLATFORM_IOS_MVK
3588
3589#ifdef VK_USE_PLATFORM_MACOS_MVK
3590void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3591 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3592 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3593 VkResult result) {
3594 if (VK_SUCCESS != result) return;
3595 RecordVulkanSurface(pSurface);
3596}
3597#endif // VK_USE_PLATFORM_MACOS_MVK
3598
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003599#ifdef VK_USE_PLATFORM_METAL_EXT
3600void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3601 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3602 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3603 VkResult result) {
3604 if (VK_SUCCESS != result) return;
3605 RecordVulkanSurface(pSurface);
3606}
3607#endif // VK_USE_PLATFORM_METAL_EXT
3608
locke-lunargd556cc32019-09-17 01:21:23 -06003609#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3610void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3611 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3612 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3613 VkResult result) {
3614 if (VK_SUCCESS != result) return;
3615 RecordVulkanSurface(pSurface);
3616}
3617#endif // VK_USE_PLATFORM_WAYLAND_KHR
3618
3619#ifdef VK_USE_PLATFORM_WIN32_KHR
3620void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3621 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3622 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3623 VkResult result) {
3624 if (VK_SUCCESS != result) return;
3625 RecordVulkanSurface(pSurface);
3626}
3627#endif // VK_USE_PLATFORM_WIN32_KHR
3628
3629#ifdef VK_USE_PLATFORM_XCB_KHR
3630void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3631 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3632 VkResult result) {
3633 if (VK_SUCCESS != result) return;
3634 RecordVulkanSurface(pSurface);
3635}
3636#endif // VK_USE_PLATFORM_XCB_KHR
3637
3638#ifdef VK_USE_PLATFORM_XLIB_KHR
3639void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3640 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3641 VkResult result) {
3642 if (VK_SUCCESS != result) return;
3643 RecordVulkanSurface(pSurface);
3644}
3645#endif // VK_USE_PLATFORM_XLIB_KHR
3646
Niklas Haas8b84af12020-04-19 22:20:11 +02003647void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3648 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3649 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3650 VkResult result) {
3651 if (VK_SUCCESS != result) return;
3652 RecordVulkanSurface(pSurface);
3653}
3654
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003655void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3656 VkSurfaceKHR surface,
3657 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3658 VkResult result) {
3659 if (VK_SUCCESS != result) return;
3660 auto surface_state = Get<SURFACE_STATE>(surface);
3661 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3662}
3663
3664void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3665 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3666 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3667 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003668
3669 if (pSurfaceInfo->surface) {
3670 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3671 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3672 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3673 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3674 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3675 assert(pd_state);
3676 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3677 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003678}
3679
3680void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3681 VkSurfaceKHR surface,
3682 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3683 VkResult result) {
3684 auto surface_state = Get<SURFACE_STATE>(surface);
3685 VkSurfaceCapabilitiesKHR caps{
3686 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3687 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3688 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3689 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3690 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3691 };
3692 surface_state->SetCapabilities(physicalDevice, caps);
3693}
3694
locke-lunargd556cc32019-09-17 01:21:23 -06003695void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3696 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3697 VkBool32 *pSupported, VkResult result) {
3698 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003699 auto surface_state = Get<SURFACE_STATE>(surface);
3700 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3701}
3702
3703void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3704 VkSurfaceKHR surface,
3705 uint32_t *pPresentModeCount,
3706 VkPresentModeKHR *pPresentModes,
3707 VkResult result) {
3708 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3709
3710 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003711 if (surface) {
3712 auto surface_state = Get<SURFACE_STATE>(surface);
3713 surface_state->SetPresentModes(physicalDevice,
3714 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3715 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3716 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3717 assert(pd_state);
3718 pd_state->surfaceless_query_state.present_modes =
3719 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3720 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003721 }
3722}
3723
3724void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3725 uint32_t *pSurfaceFormatCount,
3726 VkSurfaceFormatKHR *pSurfaceFormats,
3727 VkResult result) {
3728 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3729
3730 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003731 if (surface) {
3732 auto surface_state = Get<SURFACE_STATE>(surface);
3733 surface_state->SetFormats(physicalDevice,
3734 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3735 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3736 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3737 assert(pd_state);
3738 pd_state->surfaceless_query_state.formats =
3739 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3740 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003741 }
3742}
3743
3744void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3745 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3746 uint32_t *pSurfaceFormatCount,
3747 VkSurfaceFormat2KHR *pSurfaceFormats,
3748 VkResult result) {
3749 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3750
3751 if (pSurfaceFormats) {
3752 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003753 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3754 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3755 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003756 if (pSurfaceInfo->surface) {
3757 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3758 surface_state->SetFormats(physicalDevice, std::move(fmts));
3759 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3760 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3761 assert(pd_state);
3762 pd_state->surfaceless_query_state.formats = std::move(fmts);
3763 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003764 }
locke-lunargd556cc32019-09-17 01:21:23 -06003765}
3766
locke-lunargd556cc32019-09-17 01:21:23 -06003767void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3768 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003769 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003770 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003771 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3772}
3773
3774void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003775 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003776 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003777 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3778}
3779
3780void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3781 const VkDebugUtilsLabelEXT *pLabelInfo) {
3782 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3783
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003784 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003785 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3786 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003787 cb_state->debug_label = LoggingLabel(pLabelInfo);
3788}
3789
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003790void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3791 uint32_t queueFamilyIndex,
3792 uint32_t *pCounterCount,
3793 VkPerformanceCounterKHR *pCounters) {
3794 if (NULL == pCounters) return;
3795
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003796 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3797 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003798
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003799 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3800 queue_family_counters->counters.resize(*pCounterCount);
3801 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003802
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003803 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003804}
3805
3806void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3807 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3808 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3809 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3810 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3811}
3812
3813void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3814 VkResult result) {
3815 if (result == VK_SUCCESS) performance_lock_acquired = true;
3816}
3817
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003818void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3819 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003820 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003821 cmd_buffer.second->performance_lock_released = true;
3822 }
3823}
3824
locke-lunargd556cc32019-09-17 01:21:23 -06003825void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003826 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003827 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003828 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003829}
3830
3831void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003832 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003833 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003834 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003835}
3836
Mike Schuchardt2df08912020-12-15 16:28:09 -08003837void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3838 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003839 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003840}
3841
Mike Schuchardt2df08912020-12-15 16:28:09 -08003842void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3843 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3844 const VkAllocationCallbacks *pAllocator,
3845 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3846 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003847 if (VK_SUCCESS != result) return;
3848 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3849}
3850
3851void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003852 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3853 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003854 if (VK_SUCCESS != result) return;
3855 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3856}
3857
3858void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003859 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003860 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003861 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3862 assert(template_state);
3863 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003864 // TODO: Record template push descriptor updates
3865 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003866 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003867 }
3868 }
3869}
3870
3871void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3872 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3873 const void *pData) {
3874 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3875}
3876
3877void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003878 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003879 const void *pData) {
3880 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3881}
3882
Mike Schuchardt2df08912020-12-15 16:28:09 -08003883void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3884 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3885 VkPipelineLayout layout, uint32_t set,
3886 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003887 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003888
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003889 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003890 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003891 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003892 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003893 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003894 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003895 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003896 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003897 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003898 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003899 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3900 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003901 }
3902}
3903
3904void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3905 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003906 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003907 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003908 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003909 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003910 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003911 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003912 }
3913}
3914
3915void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3916 uint32_t *pPropertyCount,
3917 VkDisplayPlanePropertiesKHR *pProperties,
3918 VkResult result) {
3919 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3920 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3921}
3922
3923void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3924 uint32_t *pPropertyCount,
3925 VkDisplayPlaneProperties2KHR *pProperties,
3926 VkResult result) {
3927 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3928 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3929}
3930
3931void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3932 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3933 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003934 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003935 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003936 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003937}
3938
3939void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3940 uint32_t query, uint32_t index) {
3941 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003942 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003943 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003944 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003945}
3946
3947void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3948 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003949 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003950
3951 if (create_info->format != VK_FORMAT_UNDEFINED) {
3952 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003953 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003954 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3955 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003956 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003957
Jeremy Gebben082a9832021-10-28 13:40:11 -06003958 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003959}
3960
3961void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3962 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3963 const VkAllocationCallbacks *pAllocator,
3964 VkSamplerYcbcrConversion *pYcbcrConversion,
3965 VkResult result) {
3966 if (VK_SUCCESS != result) return;
3967 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3968}
3969
3970void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3971 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3972 const VkAllocationCallbacks *pAllocator,
3973 VkSamplerYcbcrConversion *pYcbcrConversion,
3974 VkResult result) {
3975 if (VK_SUCCESS != result) return;
3976 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3977}
3978
3979void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3980 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003981 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003982}
3983
3984void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3985 VkSamplerYcbcrConversion ycbcrConversion,
3986 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003987 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003988}
3989
Tony-LunarG977448c2019-12-02 14:52:02 -07003990void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3991 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003992 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003993 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003994
3995 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003996 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003997 if (!query_pool_state) return;
3998
3999 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004000 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4001 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004002 auto query_index = firstQuery + i;
4003 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004004 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004005 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004006 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004007 }
4008 }
locke-lunargd556cc32019-09-17 01:21:23 -06004009 }
4010}
4011
Tony-LunarG977448c2019-12-02 14:52:02 -07004012void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4013 uint32_t queryCount) {
4014 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4015}
4016
4017void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4018 uint32_t queryCount) {
4019 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4020}
4021
locke-lunargd556cc32019-09-17 01:21:23 -06004022void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004023 const UPDATE_TEMPLATE_STATE *template_state,
4024 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004025 // Translate the templated update into a normal update for validation...
4026 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4027 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4028 decoded_update.desc_writes.data(), 0, NULL);
4029}
4030
4031// Update the common AllocateDescriptorSetsData
4032void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004033 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004034 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004035 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004036 if (layout) {
4037 ds_data->layout_nodes[i] = layout;
4038 // Count total descriptors required per type
4039 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4040 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004041 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4042 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004043 }
4044 }
4045 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4046 }
4047}
4048
locke-lunargd556cc32019-09-17 01:21:23 -06004049void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4050 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004051 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004052 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004053}
4054
Tony-LunarG745150c2021-07-02 15:07:31 -06004055void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4056 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4057 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004058 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004059 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004060}
4061
locke-lunargd556cc32019-09-17 01:21:23 -06004062void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4063 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4064 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004065 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004066 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004067}
4068
Tony-LunarG745150c2021-07-02 15:07:31 -06004069void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4070 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4071 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4072 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004073 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004074 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004075}
4076
locke-lunargd556cc32019-09-17 01:21:23 -06004077void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4078 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004079 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004080 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004081 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004082 if (!disabled[command_buffer_state]) {
4083 cb_state->AddChild(buffer_state);
4084 }
locke-lunargd556cc32019-09-17 01:21:23 -06004085}
4086
4087void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4088 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004089 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004090 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004091 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004092 if (!disabled[command_buffer_state]) {
4093 cb_state->AddChild(buffer_state);
4094 }
locke-lunargd556cc32019-09-17 01:21:23 -06004095}
4096
4097void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004098 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004099 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004100}
4101
4102void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4103 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004104 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004105 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004106 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004107 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004108 cb_state->AddChild(buffer_state);
4109 }
locke-lunargd556cc32019-09-17 01:21:23 -06004110}
4111
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004112void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4113 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004114 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004115 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4116}
4117
4118void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4119 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004120 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004121 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4122}
4123
Tony-LunarG977448c2019-12-02 14:52:02 -07004124void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4125 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004126 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004127 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004128 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004129 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004130 auto buffer_state = Get<BUFFER_STATE>(buffer);
4131 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004132 cb_state->AddChild(buffer_state);
4133 cb_state->AddChild(count_buffer_state);
4134 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004135}
4136
locke-lunargd556cc32019-09-17 01:21:23 -06004137void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4138 VkDeviceSize offset, VkBuffer countBuffer,
4139 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4140 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004141 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004142 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004143}
4144
4145void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4146 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4147 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004148 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004149 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004150}
4151
4152void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4153 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004154 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004155 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004156 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004157 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004158 auto buffer_state = Get<BUFFER_STATE>(buffer);
4159 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004160 cb_state->AddChild(buffer_state);
4161 cb_state->AddChild(count_buffer_state);
4162 }
locke-lunargd556cc32019-09-17 01:21:23 -06004163}
4164
4165void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4166 VkDeviceSize offset, VkBuffer countBuffer,
4167 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4168 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004169 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004170 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004171}
4172
4173void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4174 VkDeviceSize offset, VkBuffer countBuffer,
4175 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4176 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004177 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004178 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004179}
4180
4181void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4182 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004183 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004184 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004185}
4186
4187void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4188 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004189 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004190 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004191 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004192 if (!disabled[command_buffer_state] && buffer_state) {
4193 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004194 }
4195}
4196
4197void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4198 VkDeviceSize offset, VkBuffer countBuffer,
4199 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4200 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004201 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004202 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004203 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004204 auto buffer_state = Get<BUFFER_STATE>(buffer);
4205 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004206 if (buffer_state) {
4207 cb_state->AddChild(buffer_state);
4208 }
4209 if (count_buffer_state) {
4210 cb_state->AddChild(count_buffer_state);
4211 }
locke-lunargd556cc32019-09-17 01:21:23 -06004212 }
4213}
4214
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004215void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4216 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4217 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4218 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4219 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4220 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4221 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004222 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004223 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004224 cb_state->hasTraceRaysCmd = true;
4225}
4226
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004227void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4228 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4229 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4230 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4231 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4232 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004233 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004234 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004235 cb_state->hasTraceRaysCmd = true;
4236}
4237
4238void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4239 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4240 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4241 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4242 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4243 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004244 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004245 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004246 cb_state->hasTraceRaysCmd = true;
4247}
4248
locke-lunargd556cc32019-09-17 01:21:23 -06004249void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4250 const VkAllocationCallbacks *pAllocator,
4251 VkShaderModule *pShaderModule, VkResult result,
4252 void *csm_state_data) {
4253 if (VK_SUCCESS != result) return;
4254 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4255
sfricke-samsung45996a42021-09-16 13:45:27 -07004256 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004257 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004258 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4259 csm_state->unique_shader_id)
4260 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004261 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004262}
4263
John Zulauf22b0fbe2019-10-15 06:26:16 -06004264void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4265 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4266 VkResult result) {
4267 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004268 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004269
4270 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4271
4272 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004273 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004274 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004275 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004276
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004277 auto format_features = GetImageFormatFeatures(
4278 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4279 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004280
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004281 auto image_state =
4282 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004283 if (!swapchain_image.fake_base_address) {
4284 auto size = image_state->fragment_encoder->TotalSize();
4285 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004286 }
4287
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004288 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004289 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004290 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004291 }
4292 }
4293
4294 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004295 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4296 }
4297}
sourav parmar35e7a002020-06-09 17:58:44 -07004298
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004299void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4300 const VkCopyAccelerationStructureInfoKHR *pInfo,
4301 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004302 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4303 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004304 if (dst_as_state != nullptr && src_as_state != nullptr) {
4305 dst_as_state->built = true;
4306 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4307 }
4308}
4309
sourav parmar35e7a002020-06-09 17:58:44 -07004310void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4311 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004312 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004313 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004314 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004315 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4316 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004317 if (dst_as_state != nullptr && src_as_state != nullptr) {
4318 dst_as_state->built = true;
4319 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004320 if (!disabled[command_buffer_state]) {
4321 cb_state->AddChild(dst_as_state);
4322 cb_state->AddChild(src_as_state);
4323 }
sourav parmar35e7a002020-06-09 17:58:44 -07004324 }
4325 }
4326}
Piers Daniell39842ee2020-07-10 16:42:33 -06004327
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004328void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4329 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4330 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4331 if (cb_state) {
4332 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4333 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4334 if (!disabled[command_buffer_state]) {
4335 cb_state->AddChild(src_as_state);
4336 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004337 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4338 if (dst_buffer) {
4339 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004340 }
4341 }
4342}
4343
4344void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4345 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4346 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4347 if (cb_state) {
4348 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4349 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004350 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4351 if (buffer_state) {
4352 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004353 }
4354 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4355 cb_state->AddChild(dst_as_state);
4356 }
4357 }
4358}
4359
Piers Daniell39842ee2020-07-10 16:42:33 -06004360void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004361 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004362 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004363}
4364
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004365void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4366 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4367 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4368}
4369
Piers Daniell39842ee2020-07-10 16:42:33 -06004370void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004371 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004372 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004373}
4374
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004375void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4376 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4377 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4378}
4379
Piers Daniell39842ee2020-07-10 16:42:33 -06004380void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4381 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004382 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004383 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004384 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004385}
4386
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004387void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4388 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004389 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004390 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4391 cb_state->primitiveTopology = primitiveTopology;
4392}
4393
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004394void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4395 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004396 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4397 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004398 uint32_t bits = (1u << viewportCount) - 1u;
4399 cb_state->viewportWithCountMask |= bits;
4400 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004401 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004402 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004403
4404 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4405 for (size_t i = 0; i < viewportCount; ++i) {
4406 cb_state->dynamicViewports[i] = pViewports[i];
4407 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004408}
4409
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004410void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4411 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004412 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004413}
4414
4415void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004416 const VkViewport *pViewports) {
4417 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004418}
4419
4420void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4421 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004422 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004423 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004424 uint32_t bits = (1u << scissorCount) - 1u;
4425 cb_state->scissorWithCountMask |= bits;
4426 cb_state->trashedScissorMask &= ~bits;
4427 cb_state->scissorWithCountCount = scissorCount;
4428 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004429}
4430
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004431void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4432 const VkRect2D *pScissors) {
4433 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4434}
4435
4436void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4437 const VkRect2D *pScissors) {
4438 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4439}
4440
4441void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4442 uint32_t bindingCount, const VkBuffer *pBuffers,
4443 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4444 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004445 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004446 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004447
4448 uint32_t end = firstBinding + bindingCount;
4449 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4450 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4451 }
4452
4453 for (uint32_t i = 0; i < bindingCount; ++i) {
4454 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004455 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004456 vertex_buffer_binding.offset = pOffsets[i];
4457 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4458 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4459 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004460 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004461 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004462 }
4463 }
4464}
4465
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004466void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4467 uint32_t bindingCount, const VkBuffer *pBuffers,
4468 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4469 const VkDeviceSize *pStrides) {
4470 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4471 CMD_BINDVERTEXBUFFERS2EXT);
4472}
4473
4474void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4475 uint32_t bindingCount, const VkBuffer *pBuffers,
4476 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4477 const VkDeviceSize *pStrides) {
4478 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4479 CMD_BINDVERTEXBUFFERS2);
4480}
4481
Piers Daniell39842ee2020-07-10 16:42:33 -06004482void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004483 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004484 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004485}
4486
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004487void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4488 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4489 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4490}
4491
Piers Daniell39842ee2020-07-10 16:42:33 -06004492void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004493 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004494 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004495}
4496
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004497void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4498 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4499 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4500}
4501
Piers Daniell39842ee2020-07-10 16:42:33 -06004502void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004503 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004504 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004505}
4506
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004507void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4508 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4509 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4510}
4511
Piers Daniell39842ee2020-07-10 16:42:33 -06004512void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4513 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004514 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004515 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004516}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004517
4518void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4519 VkBool32 depthBoundsTestEnable) {
4520 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4521 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4522}
4523
Piers Daniell39842ee2020-07-10 16:42:33 -06004524void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004525 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004526 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004527}
4528
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004529void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4530 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4531 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4532}
4533
Piers Daniell39842ee2020-07-10 16:42:33 -06004534void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4535 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4536 VkCompareOp compareOp) {
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_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004539}
locke-lunarg4189aa22020-10-21 00:23:48 -06004540
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004541void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4542 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4543 VkCompareOp compareOp) {
4544 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4545 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4546}
4547
locke-lunarg4189aa22020-10-21 00:23:48 -06004548void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4549 uint32_t discardRectangleCount,
4550 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004551 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004552 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004553}
4554
4555void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4556 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
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_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004559}
4560
4561void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4562 VkCoarseSampleOrderTypeNV sampleOrderType,
4563 uint32_t customSampleOrderCount,
4564 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004565 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004566 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004567}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004568
4569void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004570 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004571 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004572}
4573
4574void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004575 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004576 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004577}
4578
4579void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4580 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004581 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004582 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004583}
4584
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004585void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4586 VkBool32 rasterizerDiscardEnable) {
4587 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4588 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4589}
4590
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004591void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004592 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004593 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004594}
4595
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004596void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4597 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4598 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4599}
4600
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004601void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4602 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004603 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004604 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004605}
Piers Daniell924cd832021-05-18 13:48:47 -06004606
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004607void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4608 VkBool32 primitiveRestartEnable) {
4609 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4610 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4611}
4612
Piers Daniell924cd832021-05-18 13:48:47 -06004613void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4614 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4615 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4616 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004617 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004618 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4619
4620 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4621 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4622 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004623 if (pipeline_state->create_info.graphics.pDynamicState) {
4624 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4625 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004626 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4627 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4628 break;
4629 }
4630 }
4631 }
4632 }
4633 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004634}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004635
ziga-lunarg67b7c392022-03-26 01:45:34 +01004636void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4637 const VkBool32 *pColorWriteEnables) {
4638 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4639 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4640 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4641}
4642
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004643void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004644 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004645 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004646 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004647 // address is used for GPU-AV and ray tracing buffer validation
4648 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004649 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004650 }
4651}
4652
4653void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4654 VkDeviceAddress address) {
4655 RecordGetBufferDeviceAddress(pInfo, address);
4656}
4657
4658void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4659 VkDeviceAddress address) {
4660 RecordGetBufferDeviceAddress(pInfo, address);
4661}
4662
4663void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4664 VkDeviceAddress address) {
4665 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004666}
4667
4668std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4669 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004670 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004671}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004672
4673std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4674 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004675 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004676 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4677}