blob: 214989601cd8bd1bf9c56c569b25a3871c40cf6e [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++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001478 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001479 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001480 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001481 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001482 }
1483 auto submit_seq = queue_state->Submit(std::move(submission));
1484 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001485 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001486
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001487 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001488 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001489 }
1490}
1491
Tony-LunarG26fe2842021-11-16 14:07:59 -07001492void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1493 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001494 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001495 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001496 uint64_t early_retire_seq = 0;
1497 if (submitCount == 0) {
1498 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001499 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001500 early_retire_seq = queue_state->Submit(std::move(submission));
1501 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001502
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001503 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1504 CB_SUBMISSION submission;
1505 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001506 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1507 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001508 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001509 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001510 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1511 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001512 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001513 }
1514 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1515 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1516
1517 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001518 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001519 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001520 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001521 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001522 }
1523 auto submit_seq = queue_state->Submit(std::move(submission));
1524 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001525 }
locke-lunargd556cc32019-09-17 01:21:23 -06001526 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001527 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001528 }
1529}
1530
Tony-LunarG26fe2842021-11-16 14:07:59 -07001531void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1532 VkFence fence, VkResult result) {
1533 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1534}
1535
1536void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1537 VkFence fence, VkResult result) {
1538 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1539}
1540
locke-lunargd556cc32019-09-17 01:21:23 -06001541void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1542 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1543 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001544 if (VK_SUCCESS != result) {
1545 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001546 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001547 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1548 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1549 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1550
1551 layer_data::optional<DedicatedBinding> dedicated_binding;
1552
1553 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1554 if (dedicated) {
1555 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001556 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001557 assert(buffer_state);
1558 if (!buffer_state) {
1559 return;
1560 }
1561 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1562 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001563 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001564 assert(image_state);
1565 if (!image_state) {
1566 return;
1567 }
1568 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1569 }
1570 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001571 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1572 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001573 return;
1574}
1575
1576void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001577 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001578 if (mem_info) {
1579 fake_memory.Free(mem_info->fake_base_address);
1580 }
1581 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001582}
1583
1584void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1585 VkFence fence, VkResult result) {
1586 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001587 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001588
Jeremy Gebben57642982021-09-14 14:14:55 -06001589 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001590
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001591 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1592 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001593 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001594 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1595 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1596 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001597 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001598 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001599 if (buffer_state && mem_state) {
1600 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1601 }
locke-lunargd556cc32019-09-17 01:21:23 -06001602 }
1603 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001604 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1605 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1606 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001607 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001608 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001609 if (image_state && mem_state) {
1610 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1611 }
locke-lunargd556cc32019-09-17 01:21:23 -06001612 }
1613 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001614 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1615 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1616 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001617 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1618 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001619 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001620 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001621 if (image_state && mem_state) {
1622 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1623 }
locke-lunargd556cc32019-09-17 01:21:23 -06001624 }
1625 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001626 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001627 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001628 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001629 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001630 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001631 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001632 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001633 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001634 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001635 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001636 auto submit_seq = queue_state->Submit(std::move(submission));
1637 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
1639
1640 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001641 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001642 }
1643}
1644
1645void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1646 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1647 VkResult result) {
1648 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001649 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001650}
1651
Mike Schuchardt2df08912020-12-15 16:28:09 -08001652void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1653 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001654 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1655 if (semaphore_state) {
1656 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001657 }
1658}
1659
Mike Schuchardt2df08912020-12-15 16:28:09 -08001660void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001661 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001662 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001663 if (semaphore_state) {
1664 semaphore_state->RetireTimeline(pSignalInfo->value);
1665 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001666}
1667
locke-lunargd556cc32019-09-17 01:21:23 -06001668void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001669 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001670 if (mem_info) {
1671 mem_info->mapped_range.offset = offset;
1672 mem_info->mapped_range.size = size;
1673 mem_info->p_driver_data = *ppData;
1674 }
1675}
1676
locke-lunargd556cc32019-09-17 01:21:23 -06001677void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1678 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1679 if (VK_SUCCESS != result) return;
1680
1681 // When we know that all fences are complete we can clean/remove their CBs
1682 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1683 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001684 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001685 if (fence_state) {
1686 fence_state->Retire();
1687 }
locke-lunargd556cc32019-09-17 01:21:23 -06001688 }
1689 }
1690 // NOTE : Alternate case not handled here is when some fences have completed. In
1691 // this case for app to guarantee which fences completed it will have to call
1692 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1693}
1694
John Zulauff89de662020-04-13 18:57:34 -06001695void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1696 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001697 if (VK_SUCCESS != result) return;
1698
Jeremy Gebben15332642021-12-15 19:33:15 -07001699 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1700 // the application calls vkGetSemaphoreCounterValue() on each of them.
1701 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1702 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1703 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1704 if (semaphore_state) {
1705 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1706 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001707 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001708 }
1709}
1710
John Zulauff89de662020-04-13 18:57:34 -06001711void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1712 VkResult result) {
1713 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1714}
1715
1716void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1717 uint64_t timeout, VkResult result) {
1718 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1719}
1720
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001721void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1722 VkResult result) {
1723 if (VK_SUCCESS != result) return;
1724
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001725 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001726 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001727 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001728 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001729}
1730
1731void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1732 VkResult result) {
1733 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1734}
1735void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1736 VkResult result) {
1737 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1738}
1739
locke-lunargd556cc32019-09-17 01:21:23 -06001740void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1741 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001742 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001743 if (fence_state) {
1744 fence_state->Retire();
1745 }
locke-lunargd556cc32019-09-17 01:21:23 -06001746}
1747
Yilong Lice03a312022-01-02 02:08:35 -08001748void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1749 if (Get<QUEUE_STATE>(queue) == nullptr) {
1750 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1751 }
1752}
1753
1754void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1755 VkQueue *pQueue) {
1756 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1757}
1758
1759void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1760 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1761}
1762
locke-lunargd556cc32019-09-17 01:21:23 -06001763void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1764 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001765 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001766 if (queue_state) {
1767 queue_state->Retire();
1768 }
locke-lunargd556cc32019-09-17 01:21:23 -06001769}
1770
1771void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1772 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001773 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001774 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001775 }
1776}
1777
1778void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001779 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001780}
1781
1782void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1783 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001784 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001785}
1786
1787void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001788 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001789}
1790
1791void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1792 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001793 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001794}
1795
locke-lunargd556cc32019-09-17 01:21:23 -06001796void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001797 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001798 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001799 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001800 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001801 if (mem_state) {
1802 buffer_state->SetMemBinding(mem_state, memoryOffset);
1803 }
locke-lunargd556cc32019-09-17 01:21:23 -06001804 }
1805}
1806
1807void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1808 VkDeviceSize memoryOffset, VkResult result) {
1809 if (VK_SUCCESS != result) return;
1810 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1811}
1812
1813void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001814 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001815 for (uint32_t i = 0; i < bindInfoCount; i++) {
1816 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1817 }
1818}
1819
1820void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001821 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001822 for (uint32_t i = 0; i < bindInfoCount; i++) {
1823 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1824 }
1825}
1826
Spencer Fricke6c127102020-04-16 06:25:20 -07001827void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001828 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001829 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001830 buffer_state->memory_requirements_checked = true;
1831 }
1832}
1833
1834void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1835 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001836 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001837}
1838
1839void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001840 const VkBufferMemoryRequirementsInfo2 *pInfo,
1841 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001842 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001843}
1844
1845void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001846 const VkBufferMemoryRequirementsInfo2 *pInfo,
1847 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001848 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001849}
1850
Spencer Fricke6c127102020-04-16 06:25:20 -07001851void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001852 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001853 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001854 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001855 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001856 if (plane_info != nullptr) {
1857 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001858 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001859 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001860 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001861 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001862 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001863 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001864 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001865 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001866 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001867 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001868 }
locke-lunargd556cc32019-09-17 01:21:23 -06001869 }
1870}
1871
1872void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1873 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001874 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001875}
1876
1877void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1878 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001879 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001880}
1881
1882void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1883 const VkImageMemoryRequirementsInfo2 *pInfo,
1884 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001885 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001886}
1887
locke-lunargd556cc32019-09-17 01:21:23 -06001888void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1889 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1890 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001891 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001892 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001893}
1894
1895void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001896 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1897 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001898 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001899 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001900}
1901
1902void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001903 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1904 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001905 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001906 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001907}
1908
1909void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1910 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001911 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001912}
1913
1914void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1915 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001916 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001917}
1918
1919void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1920 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001921 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001922}
1923
1924void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1925 const VkAllocationCallbacks *pAllocator) {
1926 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001927 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001928 // Any bound cmd buffers are now invalid
1929 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001930 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1931 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1932 custom_border_color_sampler_count--;
1933 }
locke-lunargd556cc32019-09-17 01:21:23 -06001934 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001935 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001936}
1937
1938void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1939 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001940 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001941}
1942
1943void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1944 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001945 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001946}
1947
locke-lunargd556cc32019-09-17 01:21:23 -06001948void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1949 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001950 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1951 if (pool) {
1952 pool->Free(commandBufferCount, pCommandBuffers);
1953 }
locke-lunargd556cc32019-09-17 01:21:23 -06001954}
1955
1956void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1957 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1958 VkResult result) {
1959 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001960 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001961 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001962}
1963
1964void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1965 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1966 VkResult result) {
1967 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001968
1969 uint32_t index_count = 0, n_perf_pass = 0;
1970 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001971 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001972 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001973 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001974
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001975 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001976 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1977 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1978 switch (counter.scope) {
1979 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001980 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001981 break;
1982 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001983 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001984 break;
1985 default:
1986 break;
1987 }
1988 }
1989
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001990 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001991 }
1992
Jeremy Gebben082a9832021-10-28 13:40:11 -06001993 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 -06001994
locke-lunargd556cc32019-09-17 01:21:23 -06001995}
1996
1997void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1998 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001999 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002000}
2001
2002void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2003 VkCommandPoolResetFlags flags, VkResult result) {
2004 if (VK_SUCCESS != result) return;
2005 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002006 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2007 if (pool) {
2008 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002009 }
2010}
2011
2012void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2013 VkResult result) {
2014 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002015 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002016 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002017 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002018 }
2019 }
2020}
2021
locke-lunargd556cc32019-09-17 01:21:23 -06002022void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2023 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002024 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002025}
2026
2027void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2028 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002029 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002030}
2031
2032void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2033 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2034 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002035 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002036}
2037
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002038std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2039 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2040 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2041 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2042}
2043
locke-lunargd556cc32019-09-17 01:21:23 -06002044bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2045 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2046 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002047 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002048 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002049 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2050 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2051 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2052 cgpl_state->pipe_state.reserve(count);
2053 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002054 const auto &create_info = pCreateInfos[i];
2055 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2056 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2057
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002058 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002059 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002060 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002061 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2062 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
ziga-lunarg08c81582022-03-08 17:33:45 +01002063 } else {
ziga-lunarg08c81582022-03-08 17:33:45 +01002064 skip = true;
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002065 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002066 cgpl_state->pipe_state.push_back(
2067 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002068 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002069 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002070}
2071
2072void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2073 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2074 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2075 VkResult result, void *cgpl_state_data) {
2076 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2077 // This API may create pipelines regardless of the return value
2078 for (uint32_t i = 0; i < count; i++) {
2079 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002080 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002081 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002082 }
2083 }
2084 cgpl_state->pipe_state.clear();
2085}
2086
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002087std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2088 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2089 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2090}
2091
locke-lunargd556cc32019-09-17 01:21:23 -06002092bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2093 const VkComputePipelineCreateInfo *pCreateInfos,
2094 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002095 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002096 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2097 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2098 ccpl_state->pipe_state.reserve(count);
2099 for (uint32_t i = 0; i < count; i++) {
2100 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002101 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002102 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002103 }
2104 return false;
2105}
2106
2107void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2108 const VkComputePipelineCreateInfo *pCreateInfos,
2109 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2110 VkResult result, void *ccpl_state_data) {
2111 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2112
2113 // This API may create pipelines regardless of the return value
2114 for (uint32_t i = 0; i < count; i++) {
2115 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002116 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002117 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002118 }
2119 }
2120 ccpl_state->pipe_state.clear();
2121}
2122
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002123std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2124 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2125 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2126}
2127
locke-lunargd556cc32019-09-17 01:21:23 -06002128bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2129 uint32_t count,
2130 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2131 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002132 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002133 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2134 crtpl_state->pipe_state.reserve(count);
2135 for (uint32_t i = 0; i < count; i++) {
2136 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002137 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002138 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002139 }
2140 return false;
2141}
2142
2143void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2144 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2145 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2146 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2147 // This API may create pipelines regardless of the return value
2148 for (uint32_t i = 0; i < count; i++) {
2149 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002150 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002151 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002152 }
2153 }
2154 crtpl_state->pipe_state.clear();
2155}
2156
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002157std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2158 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2159 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2160}
2161
sourav parmarcd5fb182020-07-17 12:58:44 -07002162bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2163 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002164 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2165 const VkAllocationCallbacks *pAllocator,
2166 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002167 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002168 crtpl_state->pipe_state.reserve(count);
2169 for (uint32_t i = 0; i < count; i++) {
2170 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002171 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002172 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002173 }
2174 return false;
2175}
2176
sourav parmarcd5fb182020-07-17 12:58:44 -07002177void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2178 VkPipelineCache pipelineCache, uint32_t count,
2179 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2180 const VkAllocationCallbacks *pAllocator,
2181 VkPipeline *pPipelines, VkResult result,
2182 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002183 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2184 // This API may create pipelines regardless of the return value
2185 for (uint32_t i = 0; i < count; i++) {
2186 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002187 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002188 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002189 }
2190 }
2191 crtpl_state->pipe_state.clear();
2192}
2193
locke-lunargd556cc32019-09-17 01:21:23 -06002194void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2195 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2196 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002197 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002198 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2199 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002200 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002201 }
locke-lunargd556cc32019-09-17 01:21:23 -06002202}
2203
2204void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2205 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2206 const VkAllocationCallbacks *pAllocator,
2207 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2208 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002209 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002210}
2211
locke-lunargd556cc32019-09-17 01:21:23 -06002212void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2213 const VkAllocationCallbacks *pAllocator,
2214 VkPipelineLayout *pPipelineLayout, VkResult result) {
2215 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002216 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002217}
2218
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002219std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2220 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2221 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2222}
2223
locke-lunargd556cc32019-09-17 01:21:23 -06002224void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2225 const VkAllocationCallbacks *pAllocator,
2226 VkDescriptorPool *pDescriptorPool, VkResult result) {
2227 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002228 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002229}
2230
2231void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2232 VkDescriptorPoolResetFlags flags, VkResult result) {
2233 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002234 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2235 if (pool) {
2236 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002237 }
locke-lunargd556cc32019-09-17 01:21:23 -06002238}
2239
2240bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2241 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002242 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002243 // Always update common data
2244 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2245 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2246 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2247
2248 return false;
2249}
2250
2251// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2252void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2253 VkDescriptorSet *pDescriptorSets, VkResult result,
2254 void *ads_state_data) {
2255 if (VK_SUCCESS != result) return;
2256 // All the updates are contained in a single cvdescriptorset function
2257 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2258 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002259 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2260 if (pool_state) {
2261 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2262 }
locke-lunargd556cc32019-09-17 01:21:23 -06002263}
2264
2265void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2266 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002267 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2268 if (pool_state) {
2269 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002270 }
2271}
2272
2273void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2274 const VkWriteDescriptorSet *pDescriptorWrites,
2275 uint32_t descriptorCopyCount,
2276 const VkCopyDescriptorSet *pDescriptorCopies) {
2277 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2278 pDescriptorCopies);
2279}
2280
2281void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002282 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002283 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002284 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002285 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002286 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002287 }
2288}
2289
locke-lunargd556cc32019-09-17 01:21:23 -06002290void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2291 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002292 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002293 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002294
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002295 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002296}
2297
2298void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002299 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002300 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002301
2302 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002303}
2304
2305void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2306 VkResult result) {
2307 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002308 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2309 if (cb_state) {
2310 cb_state->Reset();
2311 }
locke-lunargd556cc32019-09-17 01:21:23 -06002312 }
2313}
2314
2315CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2316 // initially assume everything is static state
2317 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2318
2319 if (ds) {
2320 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002321 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002322 }
2323 }
locke-lunargd556cc32019-09-17 01:21:23 -06002324 return flags;
2325}
2326
2327// Validation cache:
2328// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002329
2330void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2331 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002332 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002333 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002334 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002335
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002336 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002337 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002338 const auto &create_info = pipe_state->create_info.graphics;
2339 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2340 const auto *viewport_state = create_info.pViewportState;
2341 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002342 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002343 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002344 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002345 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002346
2347 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002348 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2349 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002350 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002351 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002352 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002353 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002354 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002355 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002356
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002357 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002358 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2359 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2360 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002361 if (!has_dynamic_viewport_count) {
2362 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002363 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002364 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2365 // should become = ~uint32_t(0) if the other interpretation is correct.
2366 }
2367 }
2368 if (!has_dynamic_scissor_count) {
2369 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002370 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002371 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2372 // should become = ~uint32_t(0) if the other interpretation is correct.
2373 }
2374 }
locke-lunargd556cc32019-09-17 01:21:23 -06002375 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002376 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002377 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002378 if (!disabled[command_buffer_state]) {
2379 cb_state->AddChild(pipe_state);
2380 }
locke-lunargd556cc32019-09-17 01:21:23 -06002381}
2382
2383void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2384 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002385 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002386 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002387 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2388 cb_state->viewportMask |= bits;
2389 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002390
2391 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2392 for (size_t i = 0; i < viewportCount; ++i) {
2393 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2394 }
locke-lunargd556cc32019-09-17 01:21:23 -06002395}
2396
2397void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2398 uint32_t exclusiveScissorCount,
2399 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002400 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002401 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002402 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2403 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002404}
2405
2406void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2407 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002408 if (disabled[command_buffer_state]) return;
2409
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002410 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002411 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002412
2413 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002414 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002415 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002416 }
2417}
2418
2419void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2420 uint32_t viewportCount,
2421 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002422 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002423 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002424 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2425 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002426}
2427
2428void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2429 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2430 const VkAllocationCallbacks *pAllocator,
2431 VkAccelerationStructureNV *pAccelerationStructure,
2432 VkResult result) {
2433 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002434 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002435}
2436
Jeff Bolz95176d02020-04-01 00:36:16 -05002437void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2438 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2439 const VkAllocationCallbacks *pAllocator,
2440 VkAccelerationStructureKHR *pAccelerationStructure,
2441 VkResult result) {
2442 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002443 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2444 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002445}
2446
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002447void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2448 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2449 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2450 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2451 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002452 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002453 if (dst_as_state != nullptr) {
2454 dst_as_state->Build(&pInfos[i]);
2455 }
2456 }
2457}
2458
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002459// helper method for device side acceleration structure builds
2460void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2461 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2462 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2463 if (dst_as_state) {
2464 dst_as_state->Build(&info);
2465 }
2466 if (disabled[command_buffer_state]) {
2467 return;
2468 }
2469 if (dst_as_state) {
2470 cb_state.AddChild(dst_as_state);
2471 }
2472 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2473 if (src_as_state) {
2474 cb_state.AddChild(src_as_state);
2475 }
2476 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2477 if (scratch_buffer) {
2478 cb_state.AddChild(scratch_buffer);
2479 }
2480
2481 for (uint32_t i = 0; i < info.geometryCount; i++) {
2482 // only one of pGeometries and ppGeometries can be non-null
2483 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2484 switch (geom.geometryType) {
2485 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2486 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2487 if (vertex_buffer) {
2488 cb_state.AddChild(vertex_buffer);
2489 }
2490 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2491 if (index_buffer) {
2492 cb_state.AddChild(index_buffer);
2493 }
2494 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2495 if (transform_buffer) {
2496 cb_state.AddChild(transform_buffer);
2497 }
2498 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2499 if (motion_data) {
2500 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2501 if (motion_buffer) {
2502 cb_state.AddChild(motion_buffer);
2503 }
2504 }
2505 } break;
2506 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2507 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2508 if (data_buffer) {
2509 cb_state.AddChild(data_buffer);
2510 }
2511 } break;
2512 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2513 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2514 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2515 // easily ensure that's true.
2516 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2517 if (data_buffer) {
2518 cb_state.AddChild(data_buffer);
2519 }
2520 } break;
2521 default:
2522 break;
2523 }
2524 }
2525}
2526
sourav parmarcd5fb182020-07-17 12:58:44 -07002527void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2528 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2529 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002530 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002531 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002532 return;
2533 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002534 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002535 for (uint32_t i = 0; i < infoCount; i++) {
2536 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002537 }
2538 cb_state->hasBuildAccelerationStructureCmd = true;
2539}
2540
2541void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2542 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2543 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2544 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002545 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2546 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002547 return;
2548 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002549 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002550 for (uint32_t i = 0; i < infoCount; i++) {
2551 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002552 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002553 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2554 if (indirect_buffer) {
2555 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002556 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002557 }
2558 }
2559 cb_state->hasBuildAccelerationStructureCmd = true;
2560}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002561
locke-lunargd556cc32019-09-17 01:21:23 -06002562void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002563 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002564 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002565 if (as_state != nullptr) {
2566 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002567 as_state->memory_requirements_checked = true;
2568 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002569 as_state->build_scratch_memory_requirements_checked = true;
2570 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002571 as_state->update_scratch_memory_requirements_checked = true;
2572 }
2573 }
2574}
2575
sourav parmarcd5fb182020-07-17 12:58:44 -07002576void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2577 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002578 if (VK_SUCCESS != result) return;
2579 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002580 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002581
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002582 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002583 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002584 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002585 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002586 if (mem_state) {
2587 as_state->SetMemBinding(mem_state, info.memoryOffset);
2588 }
locke-lunargd556cc32019-09-17 01:21:23 -06002589
2590 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002591 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002592 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002593 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2594 }
2595 }
2596 }
2597}
2598
2599void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2600 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2601 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002602 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2603 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002604 return;
2605 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002606 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002607
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002608 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002609 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002610 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002611 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002612 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002613 }
locke-lunargd556cc32019-09-17 01:21:23 -06002614 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002615 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002616 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002617 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002618 cb_state->AddChild(src_as_state);
2619 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002620 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2621 if (instance_buffer) {
2622 cb_state->AddChild(instance_buffer);
2623 }
2624 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2625 if (scratch_buffer) {
2626 cb_state->AddChild(scratch_buffer);
2627 }
2628
2629 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2630 const auto& geom = pInfo->pGeometries[i];
2631
2632 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2633 if (vertex_buffer) {
2634 cb_state->AddChild(vertex_buffer);
2635 }
2636 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2637 if (index_buffer) {
2638 cb_state->AddChild(index_buffer);
2639 }
2640 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2641 if (transform_buffer) {
2642 cb_state->AddChild(transform_buffer);
2643 }
2644
2645 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2646 if (aabb_buffer) {
2647 cb_state->AddChild(aabb_buffer);
2648 }
2649 }
2650
locke-lunargd556cc32019-09-17 01:21:23 -06002651 }
2652 cb_state->hasBuildAccelerationStructureCmd = true;
2653}
2654
2655void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2656 VkAccelerationStructureNV dst,
2657 VkAccelerationStructureNV src,
2658 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002659 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002660 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002661 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2662 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002663 if (!disabled[command_buffer_state]) {
2664 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2665 }
locke-lunargd556cc32019-09-17 01:21:23 -06002666 if (dst_as_state != nullptr && src_as_state != nullptr) {
2667 dst_as_state->built = true;
2668 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002669 }
2670 }
2671}
2672
Jeff Bolz95176d02020-04-01 00:36:16 -05002673void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2674 VkAccelerationStructureKHR accelerationStructure,
2675 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002676 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002677}
2678
Jeff Bolz95176d02020-04-01 00:36:16 -05002679void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2680 VkAccelerationStructureNV accelerationStructure,
2681 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002682 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002683}
2684
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002685void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2686 uint32_t viewportCount,
2687 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002688 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002689 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002690}
2691
locke-lunargd556cc32019-09-17 01:21:23 -06002692void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002693 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002694 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002695}
2696
2697void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2698 uint16_t lineStipplePattern) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002699 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002700 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002701}
2702
2703void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2704 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002705 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002706 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002707}
2708
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002709void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2710 const VkRect2D *pScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002711 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002712 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002713 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2714 cb_state->scissorMask |= bits;
2715 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002716}
2717
locke-lunargd556cc32019-09-17 01:21:23 -06002718void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002719 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002720 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002721}
2722
2723void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2724 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002725 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002726 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002727}
2728
2729void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2730 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002731 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002732 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002733}
2734
2735void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2736 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002737 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002738 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002739}
2740
2741void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2742 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002743 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002744 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002745}
2746
locke-lunargd556cc32019-09-17 01:21:23 -06002747// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2748void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2749 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2750 uint32_t firstSet, uint32_t setCount,
2751 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2752 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002753 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002754 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002755 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002756 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002757
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002758 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2759 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002760}
2761
locke-lunargd556cc32019-09-17 01:21:23 -06002762void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2763 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2764 uint32_t set, uint32_t descriptorWriteCount,
2765 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002766 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002767 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002768 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002769}
2770
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002771void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2772 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2773 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002774 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2775 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002776 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002777 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2778 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002779
2780 auto &push_constant_data = cb_state->push_constant_data;
2781 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2782 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002783 cb_state->push_constant_pipeline_layout_set = layout;
2784
2785 auto flags = stageFlags;
2786 uint32_t bit_shift = 0;
2787 while (flags) {
2788 if (flags & 1) {
2789 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2790 const auto it = cb_state->push_constant_data_update.find(flag);
2791
2792 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002793 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002794 }
2795 }
2796 flags = flags >> 1;
2797 ++bit_shift;
2798 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002799 }
2800}
2801
locke-lunargd556cc32019-09-17 01:21:23 -06002802void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2803 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002804 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002805
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002806 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002807 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002808 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002809 cb_state->index_buffer_binding.offset = offset;
2810 cb_state->index_buffer_binding.index_type = indexType;
2811 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002812 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002813 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002814 }
locke-lunargd556cc32019-09-17 01:21:23 -06002815}
2816
2817void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2818 uint32_t bindingCount, const VkBuffer *pBuffers,
2819 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002820 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002821 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002822
2823 uint32_t end = firstBinding + bindingCount;
2824 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2825 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2826 }
2827
2828 for (uint32_t i = 0; i < bindingCount; ++i) {
2829 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002830 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002831 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002832 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2833 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002834 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002835 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002836 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002837 }
locke-lunargd556cc32019-09-17 01:21:23 -06002838 }
2839}
2840
2841void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2842 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002843 if (disabled[command_buffer_state]) return;
2844
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002845 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002846 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002847}
2848
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002849void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2850 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002851 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002852 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002853}
2854
2855void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2856 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002857 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002858 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2859
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002860 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2861 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002862}
2863
Tony-LunarGc43525f2021-11-15 16:12:38 -07002864void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2865 const VkDependencyInfo* pDependencyInfo) {
2866 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2867 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2868
2869 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2870 cb_state->RecordBarriers(*pDependencyInfo);
2871}
2872
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002873void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2874 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002875 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002876 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002877}
2878
2879void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2880 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002881 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002882 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002883}
2884
Tony-LunarGa2662db2021-11-16 07:26:24 -07002885void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2886 VkPipelineStageFlags2 stageMask) {
2887 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2888 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2889}
2890
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002891void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2892 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2893 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2894 uint32_t bufferMemoryBarrierCount,
2895 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2896 uint32_t imageMemoryBarrierCount,
2897 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002898 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2899 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002900 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2901 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002902}
2903
2904void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2905 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002906 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002907 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002908 const auto &dep_info = pDependencyInfos[i];
2909 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2910 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2911 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002912 }
2913}
2914
Tony-LunarG1364cf52021-11-17 16:10:11 -07002915void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2916 const VkDependencyInfo *pDependencyInfos) {
2917 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2918 for (uint32_t i = 0; i < eventCount; i++) {
2919 const auto &dep_info = pDependencyInfos[i];
2920 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2921 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2922 cb_state->RecordBarriers(dep_info);
2923 }
2924}
2925
Jeremy Gebben79649152021-06-22 14:46:24 -06002926void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2927 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2928 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2929 uint32_t bufferMemoryBarrierCount,
2930 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2931 uint32_t imageMemoryBarrierCount,
2932 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002933 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002934 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2935 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2936 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002937}
2938
2939void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2940 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002941 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002942 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2943 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002944}
2945
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002946void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2947 const VkDependencyInfo *pDependencyInfo) {
2948 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2949 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2950 cb_state->RecordBarriers(*pDependencyInfo);
2951}
2952
locke-lunargd556cc32019-09-17 01:21:23 -06002953void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2954 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002955 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002956
locke-lunargd556cc32019-09-17 01:21:23 -06002957 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002958 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002959 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002960 if (!disabled[query_validation]) {
2961 cb_state->BeginQuery(query);
2962 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002963 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002964 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002965 cb_state->AddChild(pool_state);
2966 }
locke-lunargd556cc32019-09-17 01:21:23 -06002967}
2968
2969void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002970 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002971 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002972 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002973 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002974 if (!disabled[query_validation]) {
2975 cb_state->EndQuery(query_obj);
2976 }
2977 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002978 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002979 cb_state->AddChild(pool_state);
2980 }
locke-lunargd556cc32019-09-17 01:21:23 -06002981}
2982
2983void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2984 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002985 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002986 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002987
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002988 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002989 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002990
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002991 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002992 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002993 cb_state->AddChild(pool_state);
2994 }
locke-lunargd556cc32019-09-17 01:21:23 -06002995}
2996
2997void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2998 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2999 VkDeviceSize dstOffset, VkDeviceSize stride,
3000 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003001 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3002
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003003 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003004 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003005 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003006 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003007 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003008 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003009}
3010
3011void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3012 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003013 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003014 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003015}
3016
3017void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3018 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3019 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003020 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003021 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003022}
3023
Tony-LunarGde9936b2021-11-17 15:34:11 -07003024void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3025 VkQueryPool queryPool, uint32_t slot) {
3026 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3027 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3028}
3029
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003030void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3031 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3032 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3033 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003034 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003035 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003036 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003037 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003038 cb_state->AddChild(pool_state);
3039 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003040 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003041}
3042
locke-lunargd556cc32019-09-17 01:21:23 -06003043void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3044 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3045 VkResult result) {
3046 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003047
Jeremy Gebben88f58142021-06-01 10:07:52 -06003048 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003049 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003050 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003051
locke-lunargd556cc32019-09-17 01:21:23 -06003052 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003053 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003054 }
3055 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003056
Jeremy Gebben9f537102021-10-05 16:37:12 -06003057 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003058 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003059}
3060
locke-lunargd556cc32019-09-17 01:21:23 -06003061void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3062 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3063 VkResult result) {
3064 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003065 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003066}
3067
Mike Schuchardt2df08912020-12-15 16:28:09 -08003068void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003069 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3070 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003071 if (VK_SUCCESS != result) return;
3072
Jeremy Gebben082a9832021-10-28 13:40:11 -06003073 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003074}
3075
Mike Schuchardt2df08912020-12-15 16:28:09 -08003076void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003077 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3078 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003079 if (VK_SUCCESS != result) return;
3080
Jeremy Gebben082a9832021-10-28 13:40:11 -06003081 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003082}
3083
locke-lunargd556cc32019-09-17 01:21:23 -06003084void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3085 const VkRenderPassBeginInfo *pRenderPassBegin,
3086 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003087 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003088 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003089}
3090
3091void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3092 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003093 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003094 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003095 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003096}
3097
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003098void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3099 uint32_t counterBufferCount,
3100 const VkBuffer *pCounterBuffers,
3101 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003102 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003103
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003104 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003105 cb_state->transform_feedback_active = true;
3106}
3107
3108void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3109 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3110 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003111 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003112
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003113 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003114 cb_state->transform_feedback_active = false;
3115}
3116
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003117void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3118 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003119 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003120
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003121 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003122 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003123 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3124 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003125}
3126
3127void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003128 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003129
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003130 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003131 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003132 cb_state->conditional_rendering_inside_render_pass = false;
3133 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003134}
3135
amhagana448ea52021-11-02 14:09:14 -04003136void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003137 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003138 cb_state->activeRenderPass = nullptr;
3139}
3140
3141void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3142 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003143 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003144 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3145}
3146
Tony-LunarG40b33882021-12-02 12:40:11 -07003147void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3148 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3149 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3150}
3151
amhagana448ea52021-11-02 14:09:14 -04003152void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3153 RecordCmdEndRenderingRenderPassState(commandBuffer);
3154}
3155
Tony-LunarG40b33882021-12-02 12:40:11 -07003156void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3157 RecordCmdEndRenderingRenderPassState(commandBuffer);
3158}
3159
Tony-LunarG977448c2019-12-02 14:52:02 -07003160void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3161 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003162 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003163 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003164 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003165}
3166
locke-lunargd556cc32019-09-17 01:21:23 -06003167void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003168 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003169 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003170}
3171
3172void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003173 const VkSubpassBeginInfo *pSubpassBeginInfo,
3174 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003175 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003176 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003177}
3178
Tony-LunarG977448c2019-12-02 14:52:02 -07003179void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003180 const VkSubpassBeginInfo *pSubpassBeginInfo,
3181 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003182 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003183 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003184}
3185
3186void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003187 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003188 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003189}
3190
3191void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003192 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003193 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003194 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003195}
3196
Tony-LunarG977448c2019-12-02 14:52:02 -07003197void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003198 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003199 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003200 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003201}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003202
locke-lunargd556cc32019-09-17 01:21:23 -06003203void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3204 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003205 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003206
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003207 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003208}
3209
3210void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3211 VkFlags flags, void **ppData, VkResult result) {
3212 if (VK_SUCCESS != result) return;
3213 RecordMappedMemory(mem, offset, size, ppData);
3214}
3215
3216void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003217 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003218 if (mem_info) {
3219 mem_info->mapped_range = MemRange();
3220 mem_info->p_driver_data = nullptr;
3221 }
3222}
3223
3224void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003225 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003226 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003227 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3228 // See: VUID-vkGetImageSubresourceLayout-image-01895
3229 image_state->fragment_encoder =
3230 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003231 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003232 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003233 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003234 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003235 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003236
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003237 if (!swapchain_image.fake_base_address) {
3238 auto size = image_state->fragment_encoder->TotalSize();
3239 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003240 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003241 // All images bound to this swapchain and index are aliases
3242 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003243 }
3244 } else {
3245 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003246 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003247 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003248 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003249 }
locke-lunargd556cc32019-09-17 01:21:23 -06003250 }
locke-lunargd556cc32019-09-17 01:21:23 -06003251 }
3252}
3253
3254void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3255 VkDeviceSize memoryOffset, VkResult result) {
3256 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003257 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003258 bind_info.image = image;
3259 bind_info.memory = mem;
3260 bind_info.memoryOffset = memoryOffset;
3261 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003262}
3263
3264void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003265 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003266 if (VK_SUCCESS != result) return;
3267 for (uint32_t i = 0; i < bindInfoCount; i++) {
3268 UpdateBindImageMemoryState(pBindInfos[i]);
3269 }
3270}
3271
3272void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003273 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003274 if (VK_SUCCESS != result) return;
3275 for (uint32_t i = 0; i < bindInfoCount; i++) {
3276 UpdateBindImageMemoryState(pBindInfos[i]);
3277 }
3278}
3279
3280void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003281 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003282 if (event_state) {
3283 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3284 }
locke-lunargd556cc32019-09-17 01:21:23 -06003285}
3286
3287void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3288 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3289 VkResult result) {
3290 if (VK_SUCCESS != result) return;
3291 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3292 pImportSemaphoreFdInfo->flags);
3293}
3294
3295void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003296 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003297 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003298 if (semaphore_state) {
3299 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003300 }
3301}
3302
3303#ifdef VK_USE_PLATFORM_WIN32_KHR
3304void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3305 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3306 if (VK_SUCCESS != result) return;
3307 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3308 pImportSemaphoreWin32HandleInfo->flags);
3309}
3310
3311void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3312 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3313 HANDLE *pHandle, VkResult result) {
3314 if (VK_SUCCESS != result) return;
3315 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3316}
3317
3318void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3319 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3320 if (VK_SUCCESS != result) return;
3321 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3322 pImportFenceWin32HandleInfo->flags);
3323}
3324
3325void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3326 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3327 HANDLE *pHandle, VkResult result) {
3328 if (VK_SUCCESS != result) return;
3329 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3330}
3331#endif
3332
3333void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3334 VkResult result) {
3335 if (VK_SUCCESS != result) return;
3336 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3337}
3338
Mike Schuchardt2df08912020-12-15 16:28:09 -08003339void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3340 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003341 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003342
3343 if (fence_node) {
3344 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003345 }
3346}
3347
3348void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3349 VkResult result) {
3350 if (VK_SUCCESS != result) return;
3351 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3352}
3353
Mike Schuchardt2df08912020-12-15 16:28:09 -08003354void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003355 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003356 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003357 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003358 }
3359}
3360
3361void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3362 VkResult result) {
3363 if (VK_SUCCESS != result) return;
3364 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3365}
3366
3367void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3368 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3369 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003370 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003371}
3372
3373void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003374 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003375 SWAPCHAIN_NODE *old_swapchain_state) {
3376 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003377 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003378 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003379 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003380 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3381 surface_state->AddParent(swapchain.get());
3382 surface_state->swapchain = swapchain.get();
3383 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003384 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003385 } else {
3386 surface_state->swapchain = nullptr;
3387 }
3388 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003389 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003390 if (old_swapchain_state) {
3391 old_swapchain_state->retired = true;
3392 }
3393 return;
3394}
3395
3396void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3397 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3398 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003399 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003400 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003401 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003402}
3403
3404void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3405 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003406 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003407}
3408
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003409void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3410 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3411 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3412 VkResult result) {
3413 if (VK_SUCCESS != result) return;
3414 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003415 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003416}
3417
locke-lunargd556cc32019-09-17 01:21:23 -06003418void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003419 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003420 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003421 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3422 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3423 if (semaphore_state) {
3424 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003425 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003426 }
3427
3428 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3429 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3430 // 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
3431 // confused itself just as much.
3432 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3433 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3434 // Mark the image as having been released to the WSI
3435 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3436 if (swapchain_data) {
3437 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3438 if (present_id_info) {
3439 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3440 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3441 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003442 }
3443 }
locke-lunargd556cc32019-09-17 01:21:23 -06003444 }
locke-lunargd556cc32019-09-17 01:21:23 -06003445}
3446
3447void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3448 const VkSwapchainCreateInfoKHR *pCreateInfos,
3449 const VkAllocationCallbacks *pAllocator,
3450 VkSwapchainKHR *pSwapchains, VkResult result) {
3451 if (pCreateInfos) {
3452 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003453 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003454 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003455 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3456 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003457 }
3458 }
3459}
3460
3461void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3462 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003463 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003464 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003465 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3466 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003467 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003468 }
3469
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003470 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003471 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003472 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3473 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003474 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003475 }
3476
3477 // Mark the image as acquired.
3478 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3479 if (swapchain_data) {
3480 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003481 }
3482}
3483
3484void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3485 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3486 VkResult result) {
3487 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3488 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3489}
3490
3491void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3492 uint32_t *pImageIndex, VkResult result) {
3493 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3494 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3495 pAcquireInfo->fence, pImageIndex);
3496}
3497
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003498std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3499 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3500}
3501
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003502void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3503 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3504 VkResult result) {
3505 if (result != VK_SUCCESS) {
3506 return;
3507 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003508 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003509 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003510 // this can fail if the allocator fails
3511 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3512 if (result != VK_SUCCESS) {
3513 return;
3514 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003515 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003516 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3517 if (result != VK_SUCCESS) {
3518 return;
3519 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003520
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003521 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003522 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003523 }
3524}
3525
3526// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003527static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003528 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003529}
3530
3531void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3532 uint32_t *pQueueFamilyPropertyCount,
3533 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003534 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3535 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003536 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003537}
3538
3539void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003540 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003541 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3542 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003543 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003544}
3545
3546void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003547 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003548 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3549 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003550 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003551}
3552void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3553 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003554 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003555}
3556
Jeremy Gebben082a9832021-10-28 13:40:11 -06003557void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003558
3559void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3560 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3561 const VkAllocationCallbacks *pAllocator,
3562 VkSurfaceKHR *pSurface, VkResult result) {
3563 if (VK_SUCCESS != result) return;
3564 RecordVulkanSurface(pSurface);
3565}
3566
3567#ifdef VK_USE_PLATFORM_ANDROID_KHR
3568void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3569 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3570 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3571 VkResult result) {
3572 if (VK_SUCCESS != result) return;
3573 RecordVulkanSurface(pSurface);
3574}
3575#endif // VK_USE_PLATFORM_ANDROID_KHR
3576
3577#ifdef VK_USE_PLATFORM_IOS_MVK
3578void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3579 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3580 VkResult result) {
3581 if (VK_SUCCESS != result) return;
3582 RecordVulkanSurface(pSurface);
3583}
3584#endif // VK_USE_PLATFORM_IOS_MVK
3585
3586#ifdef VK_USE_PLATFORM_MACOS_MVK
3587void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3588 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3589 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3590 VkResult result) {
3591 if (VK_SUCCESS != result) return;
3592 RecordVulkanSurface(pSurface);
3593}
3594#endif // VK_USE_PLATFORM_MACOS_MVK
3595
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003596#ifdef VK_USE_PLATFORM_METAL_EXT
3597void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3598 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3599 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3600 VkResult result) {
3601 if (VK_SUCCESS != result) return;
3602 RecordVulkanSurface(pSurface);
3603}
3604#endif // VK_USE_PLATFORM_METAL_EXT
3605
locke-lunargd556cc32019-09-17 01:21:23 -06003606#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3607void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3608 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3609 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3610 VkResult result) {
3611 if (VK_SUCCESS != result) return;
3612 RecordVulkanSurface(pSurface);
3613}
3614#endif // VK_USE_PLATFORM_WAYLAND_KHR
3615
3616#ifdef VK_USE_PLATFORM_WIN32_KHR
3617void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3618 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3619 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3620 VkResult result) {
3621 if (VK_SUCCESS != result) return;
3622 RecordVulkanSurface(pSurface);
3623}
3624#endif // VK_USE_PLATFORM_WIN32_KHR
3625
3626#ifdef VK_USE_PLATFORM_XCB_KHR
3627void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3628 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3629 VkResult result) {
3630 if (VK_SUCCESS != result) return;
3631 RecordVulkanSurface(pSurface);
3632}
3633#endif // VK_USE_PLATFORM_XCB_KHR
3634
3635#ifdef VK_USE_PLATFORM_XLIB_KHR
3636void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3637 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3638 VkResult result) {
3639 if (VK_SUCCESS != result) return;
3640 RecordVulkanSurface(pSurface);
3641}
3642#endif // VK_USE_PLATFORM_XLIB_KHR
3643
Niklas Haas8b84af12020-04-19 22:20:11 +02003644void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3645 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3646 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3647 VkResult result) {
3648 if (VK_SUCCESS != result) return;
3649 RecordVulkanSurface(pSurface);
3650}
3651
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003652void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3653 VkSurfaceKHR surface,
3654 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3655 VkResult result) {
3656 if (VK_SUCCESS != result) return;
3657 auto surface_state = Get<SURFACE_STATE>(surface);
3658 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3659}
3660
3661void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3662 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3663 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3664 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003665
3666 if (pSurfaceInfo->surface) {
3667 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3668 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3669 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3670 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3671 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3672 assert(pd_state);
3673 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3674 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003675}
3676
3677void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3678 VkSurfaceKHR surface,
3679 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3680 VkResult result) {
3681 auto surface_state = Get<SURFACE_STATE>(surface);
3682 VkSurfaceCapabilitiesKHR caps{
3683 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3684 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3685 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3686 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3687 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3688 };
3689 surface_state->SetCapabilities(physicalDevice, caps);
3690}
3691
locke-lunargd556cc32019-09-17 01:21:23 -06003692void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3693 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3694 VkBool32 *pSupported, VkResult result) {
3695 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003696 auto surface_state = Get<SURFACE_STATE>(surface);
3697 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3698}
3699
3700void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3701 VkSurfaceKHR surface,
3702 uint32_t *pPresentModeCount,
3703 VkPresentModeKHR *pPresentModes,
3704 VkResult result) {
3705 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3706
3707 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003708 if (surface) {
3709 auto surface_state = Get<SURFACE_STATE>(surface);
3710 surface_state->SetPresentModes(physicalDevice,
3711 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3712 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3713 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3714 assert(pd_state);
3715 pd_state->surfaceless_query_state.present_modes =
3716 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3717 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003718 }
3719}
3720
3721void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3722 uint32_t *pSurfaceFormatCount,
3723 VkSurfaceFormatKHR *pSurfaceFormats,
3724 VkResult result) {
3725 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3726
3727 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003728 if (surface) {
3729 auto surface_state = Get<SURFACE_STATE>(surface);
3730 surface_state->SetFormats(physicalDevice,
3731 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3732 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3733 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3734 assert(pd_state);
3735 pd_state->surfaceless_query_state.formats =
3736 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3737 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003738 }
3739}
3740
3741void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3742 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3743 uint32_t *pSurfaceFormatCount,
3744 VkSurfaceFormat2KHR *pSurfaceFormats,
3745 VkResult result) {
3746 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3747
3748 if (pSurfaceFormats) {
3749 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003750 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3751 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3752 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003753 if (pSurfaceInfo->surface) {
3754 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3755 surface_state->SetFormats(physicalDevice, std::move(fmts));
3756 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3757 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3758 assert(pd_state);
3759 pd_state->surfaceless_query_state.formats = std::move(fmts);
3760 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003761 }
locke-lunargd556cc32019-09-17 01:21:23 -06003762}
3763
locke-lunargd556cc32019-09-17 01:21:23 -06003764void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3765 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003766 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003767 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003768 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3769}
3770
3771void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003772 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003773 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003774 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3775}
3776
3777void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3778 const VkDebugUtilsLabelEXT *pLabelInfo) {
3779 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3780
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003781 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003782 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3783 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003784 cb_state->debug_label = LoggingLabel(pLabelInfo);
3785}
3786
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003787void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3788 uint32_t queueFamilyIndex,
3789 uint32_t *pCounterCount,
3790 VkPerformanceCounterKHR *pCounters) {
3791 if (NULL == pCounters) return;
3792
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003793 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3794 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003795
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003796 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3797 queue_family_counters->counters.resize(*pCounterCount);
3798 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003799
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003800 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003801}
3802
3803void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3804 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3805 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3806 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3807 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3808}
3809
3810void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3811 VkResult result) {
3812 if (result == VK_SUCCESS) performance_lock_acquired = true;
3813}
3814
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003815void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3816 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003817 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003818 cmd_buffer.second->performance_lock_released = true;
3819 }
3820}
3821
locke-lunargd556cc32019-09-17 01:21:23 -06003822void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003823 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003824 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003825 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003826}
3827
3828void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003829 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003830 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003831 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003832}
3833
Mike Schuchardt2df08912020-12-15 16:28:09 -08003834void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3835 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003836 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003837}
3838
Mike Schuchardt2df08912020-12-15 16:28:09 -08003839void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3840 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3841 const VkAllocationCallbacks *pAllocator,
3842 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3843 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003844 if (VK_SUCCESS != result) return;
3845 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3846}
3847
3848void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003849 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3850 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003851 if (VK_SUCCESS != result) return;
3852 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3853}
3854
3855void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003856 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003857 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003858 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3859 assert(template_state);
3860 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003861 // TODO: Record template push descriptor updates
3862 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003863 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003864 }
3865 }
3866}
3867
3868void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3869 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3870 const void *pData) {
3871 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3872}
3873
3874void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003875 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003876 const void *pData) {
3877 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3878}
3879
Mike Schuchardt2df08912020-12-15 16:28:09 -08003880void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3881 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3882 VkPipelineLayout layout, uint32_t set,
3883 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003884 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003885
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003886 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003887 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003888 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003889 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003890 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003891 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003892 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003893 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003894 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003895 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003896 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3897 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003898 }
3899}
3900
3901void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3902 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003903 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003904 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003905 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003906 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003907 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003908 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003909 }
3910}
3911
3912void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3913 uint32_t *pPropertyCount,
3914 VkDisplayPlanePropertiesKHR *pProperties,
3915 VkResult result) {
3916 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3917 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3918}
3919
3920void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3921 uint32_t *pPropertyCount,
3922 VkDisplayPlaneProperties2KHR *pProperties,
3923 VkResult result) {
3924 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3925 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3926}
3927
3928void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3929 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3930 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003931 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003932 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003933 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003934}
3935
3936void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3937 uint32_t query, uint32_t index) {
3938 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003939 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003940 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003941 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003942}
3943
3944void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3945 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003946 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003947
3948 if (create_info->format != VK_FORMAT_UNDEFINED) {
3949 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003950 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003951 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3952 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003953 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003954
Jeremy Gebben082a9832021-10-28 13:40:11 -06003955 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003956}
3957
3958void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3959 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3960 const VkAllocationCallbacks *pAllocator,
3961 VkSamplerYcbcrConversion *pYcbcrConversion,
3962 VkResult result) {
3963 if (VK_SUCCESS != result) return;
3964 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3965}
3966
3967void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3968 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3969 const VkAllocationCallbacks *pAllocator,
3970 VkSamplerYcbcrConversion *pYcbcrConversion,
3971 VkResult result) {
3972 if (VK_SUCCESS != result) return;
3973 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3974}
3975
3976void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3977 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003978 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003979}
3980
3981void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3982 VkSamplerYcbcrConversion ycbcrConversion,
3983 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003984 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003985}
3986
Tony-LunarG977448c2019-12-02 14:52:02 -07003987void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3988 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003989 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003990 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003991
3992 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003993 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003994 if (!query_pool_state) return;
3995
3996 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003997 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3998 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003999 auto query_index = firstQuery + i;
4000 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004001 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004002 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004003 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004004 }
4005 }
locke-lunargd556cc32019-09-17 01:21:23 -06004006 }
4007}
4008
Tony-LunarG977448c2019-12-02 14:52:02 -07004009void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4010 uint32_t queryCount) {
4011 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4012}
4013
4014void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4015 uint32_t queryCount) {
4016 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4017}
4018
locke-lunargd556cc32019-09-17 01:21:23 -06004019void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004020 const UPDATE_TEMPLATE_STATE *template_state,
4021 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004022 // Translate the templated update into a normal update for validation...
4023 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4024 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4025 decoded_update.desc_writes.data(), 0, NULL);
4026}
4027
4028// Update the common AllocateDescriptorSetsData
4029void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004030 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004031 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004032 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004033 if (layout) {
4034 ds_data->layout_nodes[i] = layout;
4035 // Count total descriptors required per type
4036 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4037 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004038 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4039 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004040 }
4041 }
4042 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4043 }
4044}
4045
locke-lunargd556cc32019-09-17 01:21:23 -06004046void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4047 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004048 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004049 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004050}
4051
Tony-LunarG745150c2021-07-02 15:07:31 -06004052void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4053 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4054 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004055 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004056 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004057}
4058
locke-lunargd556cc32019-09-17 01:21:23 -06004059void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4060 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4061 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004062 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004063 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004064}
4065
Tony-LunarG745150c2021-07-02 15:07:31 -06004066void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4067 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4068 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4069 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004070 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004071 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004072}
4073
locke-lunargd556cc32019-09-17 01:21:23 -06004074void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4075 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004076 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004077 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004078 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004079 if (!disabled[command_buffer_state]) {
4080 cb_state->AddChild(buffer_state);
4081 }
locke-lunargd556cc32019-09-17 01:21:23 -06004082}
4083
4084void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4085 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004086 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004087 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004088 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004089 if (!disabled[command_buffer_state]) {
4090 cb_state->AddChild(buffer_state);
4091 }
locke-lunargd556cc32019-09-17 01:21:23 -06004092}
4093
4094void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004095 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004096 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004097}
4098
4099void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4100 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004101 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004102 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004103 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004104 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004105 cb_state->AddChild(buffer_state);
4106 }
locke-lunargd556cc32019-09-17 01:21:23 -06004107}
4108
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004109void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4110 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004111 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004112 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4113}
4114
4115void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4116 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004117 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004118 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4119}
4120
Tony-LunarG977448c2019-12-02 14:52:02 -07004121void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4122 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004123 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004124 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004125 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004126 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004127 auto buffer_state = Get<BUFFER_STATE>(buffer);
4128 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004129 cb_state->AddChild(buffer_state);
4130 cb_state->AddChild(count_buffer_state);
4131 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004132}
4133
locke-lunargd556cc32019-09-17 01:21:23 -06004134void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4135 VkDeviceSize offset, VkBuffer countBuffer,
4136 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4137 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004138 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004139 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004140}
4141
4142void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4143 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4144 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004145 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004146 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004147}
4148
4149void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4150 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004151 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004152 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004153 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004154 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004155 auto buffer_state = Get<BUFFER_STATE>(buffer);
4156 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004157 cb_state->AddChild(buffer_state);
4158 cb_state->AddChild(count_buffer_state);
4159 }
locke-lunargd556cc32019-09-17 01:21:23 -06004160}
4161
4162void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4163 VkDeviceSize offset, VkBuffer countBuffer,
4164 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4165 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004166 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004167 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004168}
4169
4170void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4171 VkDeviceSize offset, VkBuffer countBuffer,
4172 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4173 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004174 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004175 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004176}
4177
4178void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4179 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004180 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004181 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004182}
4183
4184void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4185 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004186 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004187 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004188 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004189 if (!disabled[command_buffer_state] && buffer_state) {
4190 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004191 }
4192}
4193
4194void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4195 VkDeviceSize offset, VkBuffer countBuffer,
4196 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4197 uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004198 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004199 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004200 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004201 auto buffer_state = Get<BUFFER_STATE>(buffer);
4202 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004203 if (buffer_state) {
4204 cb_state->AddChild(buffer_state);
4205 }
4206 if (count_buffer_state) {
4207 cb_state->AddChild(count_buffer_state);
4208 }
locke-lunargd556cc32019-09-17 01:21:23 -06004209 }
4210}
4211
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004212void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4213 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4214 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4215 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4216 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4217 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4218 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004219 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004220 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004221 cb_state->hasTraceRaysCmd = true;
4222}
4223
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004224void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4225 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4226 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4227 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4228 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4229 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004230 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004231 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004232 cb_state->hasTraceRaysCmd = true;
4233}
4234
4235void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4236 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4237 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4238 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4239 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4240 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004241 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004242 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004243 cb_state->hasTraceRaysCmd = true;
4244}
4245
locke-lunargd556cc32019-09-17 01:21:23 -06004246void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4247 const VkAllocationCallbacks *pAllocator,
4248 VkShaderModule *pShaderModule, VkResult result,
4249 void *csm_state_data) {
4250 if (VK_SUCCESS != result) return;
4251 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4252
sfricke-samsung45996a42021-09-16 13:45:27 -07004253 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004254 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004255 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4256 csm_state->unique_shader_id)
4257 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004258 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004259}
4260
John Zulauf22b0fbe2019-10-15 06:26:16 -06004261void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4262 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4263 VkResult result) {
4264 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004265 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004266
4267 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4268
4269 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004270 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004271 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004272 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004273
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004274 auto format_features = GetImageFormatFeatures(
4275 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4276 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004277
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004278 auto image_state =
4279 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004280 if (!swapchain_image.fake_base_address) {
4281 auto size = image_state->fragment_encoder->TotalSize();
4282 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004283 }
4284
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004285 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004286 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004287 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004288 }
4289 }
4290
4291 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004292 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4293 }
4294}
sourav parmar35e7a002020-06-09 17:58:44 -07004295
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004296void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4297 const VkCopyAccelerationStructureInfoKHR *pInfo,
4298 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004299 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4300 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004301 if (dst_as_state != nullptr && src_as_state != nullptr) {
4302 dst_as_state->built = true;
4303 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4304 }
4305}
4306
sourav parmar35e7a002020-06-09 17:58:44 -07004307void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4308 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004309 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004310 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004311 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004312 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4313 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004314 if (dst_as_state != nullptr && src_as_state != nullptr) {
4315 dst_as_state->built = true;
4316 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004317 if (!disabled[command_buffer_state]) {
4318 cb_state->AddChild(dst_as_state);
4319 cb_state->AddChild(src_as_state);
4320 }
sourav parmar35e7a002020-06-09 17:58:44 -07004321 }
4322 }
4323}
Piers Daniell39842ee2020-07-10 16:42:33 -06004324
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004325void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4326 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4327 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4328 if (cb_state) {
4329 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4330 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4331 if (!disabled[command_buffer_state]) {
4332 cb_state->AddChild(src_as_state);
4333 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004334 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4335 if (dst_buffer) {
4336 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004337 }
4338 }
4339}
4340
4341void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4342 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4343 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4344 if (cb_state) {
4345 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4346 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004347 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4348 if (buffer_state) {
4349 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004350 }
4351 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4352 cb_state->AddChild(dst_as_state);
4353 }
4354 }
4355}
4356
Piers Daniell39842ee2020-07-10 16:42:33 -06004357void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004358 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004359 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004360}
4361
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004362void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4363 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4364 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4365}
4366
Piers Daniell39842ee2020-07-10 16:42:33 -06004367void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004368 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004369 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004370}
4371
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004372void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4373 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4374 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4375}
4376
Piers Daniell39842ee2020-07-10 16:42:33 -06004377void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4378 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004379 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004380 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004381 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004382}
4383
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004384void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4385 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004386 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004387 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4388 cb_state->primitiveTopology = primitiveTopology;
4389}
4390
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004391void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4392 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004393 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4394 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004395 uint32_t bits = (1u << viewportCount) - 1u;
4396 cb_state->viewportWithCountMask |= bits;
4397 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004398 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004399 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004400
4401 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4402 for (size_t i = 0; i < viewportCount; ++i) {
4403 cb_state->dynamicViewports[i] = pViewports[i];
4404 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004405}
4406
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004407void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4408 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004409 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004410}
4411
4412void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004413 const VkViewport *pViewports) {
4414 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004415}
4416
4417void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4418 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004419 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004420 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004421 uint32_t bits = (1u << scissorCount) - 1u;
4422 cb_state->scissorWithCountMask |= bits;
4423 cb_state->trashedScissorMask &= ~bits;
4424 cb_state->scissorWithCountCount = scissorCount;
4425 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004426}
4427
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004428void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4429 const VkRect2D *pScissors) {
4430 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4431}
4432
4433void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4434 const VkRect2D *pScissors) {
4435 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4436}
4437
4438void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4439 uint32_t bindingCount, const VkBuffer *pBuffers,
4440 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4441 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004442 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004443 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004444
4445 uint32_t end = firstBinding + bindingCount;
4446 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4447 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4448 }
4449
4450 for (uint32_t i = 0; i < bindingCount; ++i) {
4451 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004452 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004453 vertex_buffer_binding.offset = pOffsets[i];
4454 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4455 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4456 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004457 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004458 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004459 }
4460 }
4461}
4462
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004463void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4464 uint32_t bindingCount, const VkBuffer *pBuffers,
4465 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4466 const VkDeviceSize *pStrides) {
4467 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4468 CMD_BINDVERTEXBUFFERS2EXT);
4469}
4470
4471void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4472 uint32_t bindingCount, const VkBuffer *pBuffers,
4473 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4474 const VkDeviceSize *pStrides) {
4475 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4476 CMD_BINDVERTEXBUFFERS2);
4477}
4478
Piers Daniell39842ee2020-07-10 16:42:33 -06004479void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004480 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004481 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004482}
4483
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004484void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4485 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4486 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4487}
4488
Piers Daniell39842ee2020-07-10 16:42:33 -06004489void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004490 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004491 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004492}
4493
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004494void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4495 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4496 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4497}
4498
Piers Daniell39842ee2020-07-10 16:42:33 -06004499void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004500 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004501 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004502}
4503
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004504void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4505 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4506 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4507}
4508
Piers Daniell39842ee2020-07-10 16:42:33 -06004509void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4510 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004511 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004512 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004513}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004514
4515void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4516 VkBool32 depthBoundsTestEnable) {
4517 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4518 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4519}
4520
Piers Daniell39842ee2020-07-10 16:42:33 -06004521void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004522 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004523 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004524}
4525
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004526void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4527 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4528 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4529}
4530
Piers Daniell39842ee2020-07-10 16:42:33 -06004531void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4532 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4533 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004534 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004535 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004536}
locke-lunarg4189aa22020-10-21 00:23:48 -06004537
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004538void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4539 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4540 VkCompareOp compareOp) {
4541 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4542 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4543}
4544
locke-lunarg4189aa22020-10-21 00:23:48 -06004545void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4546 uint32_t discardRectangleCount,
4547 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004548 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004549 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004550}
4551
4552void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4553 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004554 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004555 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004556}
4557
4558void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4559 VkCoarseSampleOrderTypeNV sampleOrderType,
4560 uint32_t customSampleOrderCount,
4561 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004562 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004563 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004564}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004565
4566void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004567 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004568 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004569}
4570
4571void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004572 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004573 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004574}
4575
4576void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4577 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004578 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004579 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004580}
4581
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004582void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4583 VkBool32 rasterizerDiscardEnable) {
4584 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4585 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4586}
4587
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004588void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004589 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004590 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004591}
4592
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004593void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4594 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4595 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4596}
4597
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004598void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4599 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004600 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004601 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004602}
Piers Daniell924cd832021-05-18 13:48:47 -06004603
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004604void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4605 VkBool32 primitiveRestartEnable) {
4606 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4607 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4608}
4609
Piers Daniell924cd832021-05-18 13:48:47 -06004610void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4611 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4612 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4613 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004614 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004615 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4616
4617 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4618 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4619 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004620 if (pipeline_state->create_info.graphics.pDynamicState) {
4621 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4622 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004623 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4624 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4625 break;
4626 }
4627 }
4628 }
4629 }
4630 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004631}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004632
ziga-lunarg67b7c392022-03-26 01:45:34 +01004633void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4634 const VkBool32 *pColorWriteEnables) {
4635 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4636 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4637 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4638}
4639
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004640void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004641 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004642 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004643 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004644 // address is used for GPU-AV and ray tracing buffer validation
4645 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004646 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004647 }
4648}
4649
4650void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4651 VkDeviceAddress address) {
4652 RecordGetBufferDeviceAddress(pInfo, address);
4653}
4654
4655void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4656 VkDeviceAddress address) {
4657 RecordGetBufferDeviceAddress(pInfo, address);
4658}
4659
4660void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4661 VkDeviceAddress address) {
4662 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004663}
4664
4665std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4666 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004667 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004668}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004669
4670std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4671 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004672 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004673 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4674}