blob: fc39b00104268c15e1f6eb5804d246837dc60dab [file] [log] [blame]
Yilong Lid23bc292022-01-02 22:06:12 -08001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Tobias Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
locke-lunargd556cc32019-09-17 01:21:23 -06006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Mark Lobodzinski <mark@lunarg.com>
20 * Author: Dave Houlton <daveh@lunarg.com>
21 * Shannon McPherson <shannon@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000022 * Author: Tobias Hector <tobias.hector@amd.com>
locke-lunargd556cc32019-09-17 01:21:23 -060023 */
24
David Zhao Akeley44139b12021-04-26 16:16:13 -070025#include <algorithm>
locke-lunargd556cc32019-09-17 01:21:23 -060026#include <cmath>
locke-lunargd556cc32019-09-17 01:21:23 -060027
28#include "vk_enum_string_helper.h"
29#include "vk_format_utils.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33#include "vk_typemap_helper.h"
34
35#include "chassis.h"
36#include "state_tracker.h"
37#include "shader_validation.h"
Jeremy Gebben74aa7622020-12-15 11:18:00 -070038#include "sync_utils.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060039#include "cmd_buffer_state.h"
40#include "render_pass_state.h"
locke-lunarg4189aa22020-10-21 00:23:48 -060041
John Zulauf2bc1fde2020-04-24 15:09:51 -060042// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
43// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060044static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
45 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060046 const VkImageView *attachments = fb_state.createInfo.pAttachments;
47 uint32_t count = fb_state.createInfo.attachmentCount;
48 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070049 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060050 if (framebuffer_attachments) {
51 attachments = framebuffer_attachments->pAttachments;
52 count = framebuffer_attachments->attachmentCount;
53 }
54 }
55 return std::make_pair(count, attachments);
56}
57
John Zulauf64ffe552021-02-06 10:25:07 -070058template <typename ImageViewPointer, typename Get>
59std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
60 const Get &get_fn) {
61 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060062
63 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
64 const auto attachment_count = count_attachment.first;
65 const auto *attachments = count_attachment.second;
66 views.resize(attachment_count, nullptr);
67 for (uint32_t i = 0; i < attachment_count; i++) {
68 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070069 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060070 }
71 }
72 return views;
73}
74
Jeremy Gebben9f537102021-10-05 16:37:12 -060075std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070076 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060077 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070078 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
79}
80
locke-lunargd556cc32019-09-17 01:21:23 -060081#ifdef VK_USE_PLATFORM_ANDROID_KHR
82// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
83// This could also move into a seperate core_validation_android.cpp file... ?
84
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060085template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020086VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060087 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070088 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -060089 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -070090 // VUID 01894 will catch if not found in map
91 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
92 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060093 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -070094 }
locke-lunargd556cc32019-09-17 01:21:23 -060095 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060096 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -060097}
98
Spencer Fricke6bba8c72020-04-06 07:41:21 -070099void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
100 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
101 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200102 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
103 if (ahb_format_props2) {
104 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
105 } else {
106 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
107 if (ahb_format_props) {
108 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
109 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
110 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700111 }
112}
113
locke-lunargd556cc32019-09-17 01:21:23 -0600114#else
115
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600116template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200117VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600118 return 0;
119}
locke-lunargd556cc32019-09-17 01:21:23 -0600120
121#endif // VK_USE_PLATFORM_ANDROID_KHR
122
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200123VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
124 VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200125 VkFormatFeatureFlags2KHR format_features = 0;
126
Petr Kraus44f1c482020-04-25 20:09:25 +0200127 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
128 // if format is AHB external format then the features are already set
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200129 if (has_format_feature2) {
130 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200131 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200132 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
133
134 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
135
136 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
137 VkImageDrmFormatModifierPropertiesEXT drm_format_props = {
138 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
139 nullptr,
140 };
141
142 // Find the image modifier
143 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
144
145 std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
146 drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
147 fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
148
149 // Second query to have all the modifiers filled
150 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
151
152 // Look for the image modifier in the list
153 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
154 if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
155 format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
156 break;
157 }
158 }
159 } else {
160 format_features =
161 (tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
162 }
163 } else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600164 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
165 nullptr};
166 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200167
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
169 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
170 nullptr};
171 format_properties_2.pNext = (void *)&drm_properties_list;
172 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
173 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
174 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
175 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
176 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200177
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600178 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
179 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
180 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
181 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200182 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200183 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600184 } else {
185 VkFormatProperties format_properties;
186 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
187 format_features =
188 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200189 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600190 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200191}
192
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700193std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
194 VkFormatFeatureFlags2KHR features) {
195 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, features);
196}
197
198std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
199 VkSwapchainKHR swapchain, uint32_t swapchain_index,
200 VkFormatFeatureFlags2KHR features) {
201 return std::make_shared<IMAGE_STATE>(this, img, pCreateInfo, swapchain, swapchain_index, features);
202}
203
locke-lunargd556cc32019-09-17 01:21:23 -0600204void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
205 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
206 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200207 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700208 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600209 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600210 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600211 if (format_features == 0) {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200212 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
213 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
214 pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600215 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -0700216 Add(CreateImageState(*pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600217}
218
219void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600220 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600221}
222
223void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
224 VkImageLayout imageLayout, const VkClearColorValue *pColor,
225 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600226 if (disabled[command_buffer_state]) return;
227
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700228 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600229 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600230 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600231 }
232}
233
234void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
235 VkImageLayout imageLayout,
236 const VkClearDepthStencilValue *pDepthStencil,
237 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600238 if (disabled[command_buffer_state]) return;
239
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700240 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600241 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600242 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600243 }
244}
245
246void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
247 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
248 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600249 if (disabled[command_buffer_state]) return;
250
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700251 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600252 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600253}
254
Jeff Leger178b1e52020-10-05 12:22:23 -0400255void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
256 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600257 if (disabled[command_buffer_state]) return;
258
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700259 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600260 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
261 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400262}
263
Tony-LunarGb61514a2021-11-02 12:36:51 -0600264void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
265 if (disabled[command_buffer_state]) return;
266
267 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
268 cb_node->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
269 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
270}
271
locke-lunargd556cc32019-09-17 01:21:23 -0600272void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
273 VkImageLayout srcImageLayout, VkImage dstImage,
274 VkImageLayout dstImageLayout, uint32_t regionCount,
275 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600276 if (disabled[command_buffer_state]) return;
277
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700278 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600279 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600280}
281
Jeff Leger178b1e52020-10-05 12:22:23 -0400282void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
283 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600284 if (disabled[command_buffer_state]) return;
285
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700286 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600287 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
288 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400289}
290
Tony-LunarG562fc102021-11-12 13:58:35 -0700291void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
292 const VkResolveImageInfo2 *pResolveImageInfo) {
293 if (disabled[command_buffer_state]) return;
294
295 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
296 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
297 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
298}
299
locke-lunargd556cc32019-09-17 01:21:23 -0600300void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
301 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
302 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600303 if (disabled[command_buffer_state]) return;
304
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700305 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600306 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600307}
308
Jeff Leger178b1e52020-10-05 12:22:23 -0400309void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
310 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600311 if (disabled[command_buffer_state]) return;
312
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700313 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600314 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
315 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400316}
317
Tony-LunarG542ae912021-11-04 16:06:44 -0600318void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
319 if (disabled[command_buffer_state]) return;
320
321 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
322 cb_node->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
323 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
324}
325
locke-lunargd556cc32019-09-17 01:21:23 -0600326void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
327 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
328 VkResult result) {
329 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600330
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600331 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600332
James Rumble2f6e7bb2021-07-13 15:21:20 +0100333 if (pCreateInfo) {
334 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -0700335 if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700336 WriteLockGuard guard(buffer_address_lock_);
James Rumble2f6e7bb2021-07-13 15:21:20 +0100337 // address is used for GPU-AV and ray tracing buffer validation
338 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700339 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
James Rumble2f6e7bb2021-07-13 15:21:20 +0100340 }
341 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600342 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600343}
344
345void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
346 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
347 VkResult result) {
348 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600349
Jeremy Gebben9f537102021-10-05 16:37:12 -0600350 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600351
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200352 VkFormatFeatureFlags2KHR buffer_features;
353 if (has_format_feature2) {
354 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
355 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
356 DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
357 buffer_features = fmt_props_3.bufferFeatures;
358 } else {
359 VkFormatProperties format_properties;
360 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
361 buffer_features = format_properties.bufferFeatures;
362 }
locke-lunarg25b6c352020-08-06 17:44:18 -0600363
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200364 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600365}
366
367void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
368 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
369 VkResult result) {
370 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600371 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700372
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200373 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600374 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700375 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600376 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700377 } else {
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200378 format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
379 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
380 image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700381 }
382
locke-lunarg9939d4b2020-10-26 20:11:08 -0600383 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600384 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600385 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700386 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600387 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700388 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600389 image_format_info.type = image_state->createInfo.imageType;
390 image_format_info.format = image_state->createInfo.format;
391 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600392 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
393 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600394 image_format_info.flags = image_state->createInfo.flags;
395
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600396 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600397
398 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
399 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600400
Jeremy Gebben082a9832021-10-28 13:40:11 -0600401 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600402}
403
404void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
405 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600406 if (disabled[command_buffer_state]) return;
407
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700408 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600409 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600410}
411
Jeff Leger178b1e52020-10-05 12:22:23 -0400412void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600413 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600414 if (disabled[command_buffer_state]) return;
415
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700416 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600417 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
418 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400419}
420
Tony-LunarGef035472021-11-02 10:23:33 -0600421void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
422 if (disabled[command_buffer_state]) return;
423
424 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
425 cb_node->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
426 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
427}
428
locke-lunargd556cc32019-09-17 01:21:23 -0600429void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
430 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600431 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600432}
433
434void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -0700435 auto buffer_state = Get<BUFFER_STATE>(buffer);
436 if (buffer_state) {
437 WriteLockGuard guard(buffer_address_lock_);
438 buffer_address_map_.erase_range(buffer_state->DeviceAddressRange());
439 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600440 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600441}
442
443void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
444 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600445 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600446}
447
448void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
449 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600450 if (disabled[command_buffer_state]) return;
451
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700452 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600453 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600454}
455
456void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
457 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
458 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600459 if (disabled[command_buffer_state]) return;
460
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700461 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600462
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600463 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600464}
465
Jeff Leger178b1e52020-10-05 12:22:23 -0400466void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
467 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600468 if (disabled[command_buffer_state]) return;
469
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700470 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600471 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
472 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400473}
474
Tony-LunarGaf3632a2021-11-10 15:51:57 -0700475void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
476 const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
477 if (disabled[command_buffer_state]) return;
478
479 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
480 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
481 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
482}
483
locke-lunargd556cc32019-09-17 01:21:23 -0600484void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
485 VkImageLayout dstImageLayout, uint32_t regionCount,
486 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600487 if (disabled[command_buffer_state]) return;
488
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700489 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600490 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600491}
492
Jeff Leger178b1e52020-10-05 12:22:23 -0400493void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
494 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600495 if (disabled[command_buffer_state]) return;
496
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700497 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600498 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
499 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400500}
501
Tony Barbour845d29b2021-11-09 11:43:14 -0700502void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
503 const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
504 if (disabled[command_buffer_state]) return;
505
506 auto cb_node = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
507 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
508 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
509}
510
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700511// Gets union of all features defined by Potential Format Features
512// except, does not handle the external format case for AHB as that only can be used for sampled images
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200513VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
514 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700515
516 if (format != VK_FORMAT_UNDEFINED) {
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200517 if (has_format_feature2) {
518 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +0200519 auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
520 IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200521 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100522
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200523 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100524
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200525 format_features |= fmt_props_3.linearTilingFeatures;
526 format_features |= fmt_props_3.optimalTilingFeatures;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100527
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200528 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
529 std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
530 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
531 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
532 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100533
Lionel Landwerlind0f84e42021-12-07 15:46:09 +0200534 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
535 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
536 }
537 }
538 } else {
539 VkFormatProperties format_properties;
540 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
541 format_features |= format_properties.linearTilingFeatures;
542 format_features |= format_properties.optimalTilingFeatures;
543
544 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
545 auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
546 auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
547
548 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
549
550 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
551 drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
552 fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
553 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
554
555 for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
556 format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
557 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700558 }
559 }
560 }
561
562 return format_features;
563}
564
locke-lunargd556cc32019-09-17 01:21:23 -0600565void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
566 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
567 VkResult result) {
568 if (VK_SUCCESS != result) return;
569
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600570 // The current object represents the VkInstance, look up / create the object for the device.
Locke Linf3873542021-04-26 11:25:10 -0600571 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
572 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600573 ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
Locke Linf3873542021-04-26 11:25:10 -0600574
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600575 device_state->instance_state = this;
576 // Save local link to this device's physical device state
577 device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
578 // finish setup in the object representing the device
579 device_state->CreateDevice(pCreateInfo);
580}
581
582void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -0600583 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
584 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700585 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600586 if (features2) {
587 enabled_features_found = &(features2->features);
588 }
589 }
590
locke-lunargd556cc32019-09-17 01:21:23 -0600591 if (nullptr == enabled_features_found) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600592 enabled_features.core = {};
locke-lunargd556cc32019-09-17 01:21:23 -0600593 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600594 enabled_features.core = *enabled_features_found;
locke-lunargd556cc32019-09-17 01:21:23 -0600595 }
596
Tony-LunarG273f32f2021-09-28 08:56:30 -0600597 const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
598 if (vulkan_13_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600599 enabled_features.core13 = *vulkan_13_features;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600600 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600601 enabled_features.core13 = {};
Tony-LunarG273f32f2021-09-28 08:56:30 -0600602 const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
603 if (image_robustness_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600604 enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600605 }
606
607 const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
608 if (inline_uniform_block_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600609 enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
610 enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600611 inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
612 }
613
614 const auto *pipeline_creation_cache_control_features =
615 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
616 if (pipeline_creation_cache_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600617 enabled_features.core13.pipelineCreationCacheControl =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600618 pipeline_creation_cache_control_features->pipelineCreationCacheControl;
619 }
620
621 const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
622 if (private_data_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600623 enabled_features.core13.privateData = private_data_features->privateData;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600624 }
625
626 const auto *demote_to_helper_invocation_features =
627 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
628 if (demote_to_helper_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600629 enabled_features.core13.shaderDemoteToHelperInvocation =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600630 demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
631 }
632
633 const auto *terminate_invocation_features =
634 LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
635 if (terminate_invocation_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600636 enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600637 }
638
639 const auto *subgroup_size_control_features =
640 LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
641 if (subgroup_size_control_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600642 enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
643 enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600644 }
645
646 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
647 if (synchronization2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600648 enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600649 }
650
651 const auto *texture_compression_astchdr_features =
652 LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
653 if (texture_compression_astchdr_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600654 enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600655 }
656
657 const auto *initialize_workgroup_memory_features =
658 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
659 if (initialize_workgroup_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600660 enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
Tony-LunarG273f32f2021-09-28 08:56:30 -0600661 initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
662 }
663
664 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
665 if (dynamic_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600666 enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600667 }
668
669 const auto *shader_integer_dot_product_features =
670 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
671 if (shader_integer_dot_product_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600672 enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600673 }
674
675 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
676 if (maintenance4_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600677 enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
Tony-LunarG273f32f2021-09-28 08:56:30 -0600678 }
679 }
680
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700681 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700682 if (vulkan_12_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600683 enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700684 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700685 // Set Extension Feature Aliases to false as there is no struct to check
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600686 enabled_features.core12.drawIndirectCount = VK_FALSE;
687 enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
688 enabled_features.core12.descriptorIndexing = VK_FALSE;
689 enabled_features.core12.samplerFilterMinmax = VK_FALSE;
690 enabled_features.core12.shaderOutputLayer = VK_FALSE;
691 enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
692 enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700693
694 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700695
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700696 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700697 if (eight_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600698 enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
699 enabled_features.core12.uniformAndStorageBuffer8BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700700 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600701 enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700702 }
703
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700704 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700705 if (float16_int8_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600706 enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
707 enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700708 }
709
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700710 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700711 if (descriptor_indexing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600712 enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700713 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600714 enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700715 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600716 enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700717 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600718 enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700719 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600720 enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700721 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600722 enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700723 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600724 enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700725 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600726 enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700727 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600728 enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700729 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600730 enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700731 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600732 enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700733 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600734 enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700735 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600736 enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600738 enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700739 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600740 enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700741 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600742 enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700743 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600744 enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700745 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600746 enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
747 enabled_features.core12.descriptorBindingVariableDescriptorCount =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700748 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600749 enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700750 }
751
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700752 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700753 if (scalar_block_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600754 enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700755 }
756
757 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700758 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700759 if (imageless_framebuffer_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600760 enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700761 }
762
763 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700764 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700765 if (uniform_buffer_standard_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600766 enabled_features.core12.uniformBufferStandardLayout =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700768 }
769
770 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700771 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700772 if (subgroup_extended_types_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600773 enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700774 }
775
776 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700777 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700778 if (separate_depth_stencil_layouts_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600779 enabled_features.core12.separateDepthStencilLayouts =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700780 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700781 }
782
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700783 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700784 if (host_query_reset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600785 enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700786 }
787
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700788 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700789 if (timeline_semaphore_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600790 enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700791 }
792
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700793 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700794 if (buffer_device_address) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600795 enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
796 enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
797 enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700798 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800799
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700800 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800801 if (atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600802 enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
803 enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800804 }
805
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700806 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800807 if (memory_model_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600808 enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
809 enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
810 enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800811 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
812 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700813 }
814
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700815 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700816 if (vulkan_11_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600817 enabled_features.core11 = *vulkan_11_features;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700818 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700819 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700820
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700821 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700822 if (sixteen_bit_storage_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600823 enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
824 enabled_features.core11.uniformAndStorageBuffer16BitAccess =
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700825 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600826 enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
827 enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700828 }
829
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700830 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700831 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600832 enabled_features.core11.multiview = multiview_features->multiview;
833 enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
834 enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700835 }
836
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700837 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700838 if (variable_pointers_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600839 enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
840 enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700841 }
842
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700843 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700844 if (protected_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600845 enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700846 }
847
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700848 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700849 if (ycbcr_conversion_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600850 enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700851 }
852
853 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700854 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700855 if (shader_draw_parameters_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600856 enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700857 }
858 }
859
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700860 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600861 if (device_group_ci) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600862 physical_device_count = device_group_ci->physicalDeviceCount;
863 device_group_create_info = *device_group_ci;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600864 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600865 physical_device_count = 1;
Tony-LunarGca4891a2020-08-10 15:46:46 -0600866 }
locke-lunargd556cc32019-09-17 01:21:23 -0600867
sfricke-samsung828e59d2021-08-22 23:20:49 -0700868 // Features from other extensions passesd in create info
869 {
870 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
871 if (exclusive_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600872 enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700873 }
locke-lunargd556cc32019-09-17 01:21:23 -0600874
sfricke-samsung828e59d2021-08-22 23:20:49 -0700875 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
876 if (shading_rate_image_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600877 enabled_features.shading_rate_image_features = *shading_rate_image_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700878 }
locke-lunargd556cc32019-09-17 01:21:23 -0600879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
881 if (mesh_shader_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600882 enabled_features.mesh_shader_features = *mesh_shader_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700883 }
locke-lunargd556cc32019-09-17 01:21:23 -0600884
sfricke-samsung828e59d2021-08-22 23:20:49 -0700885 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
886 if (transform_feedback_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600887 enabled_features.transform_feedback_features = *transform_feedback_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700888 }
locke-lunargd556cc32019-09-17 01:21:23 -0600889
sfricke-samsung828e59d2021-08-22 23:20:49 -0700890 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
891 if (vtx_attrib_div_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600892 enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700893 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700894
sfricke-samsung828e59d2021-08-22 23:20:49 -0700895 const auto *buffer_device_address_ext_features =
896 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
897 if (buffer_device_address_ext_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600898 enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700899 }
locke-lunargd556cc32019-09-17 01:21:23 -0600900
sfricke-samsung828e59d2021-08-22 23:20:49 -0700901 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
902 if (cooperative_matrix_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600903 enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700904 }
locke-lunargd556cc32019-09-17 01:21:23 -0600905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 const auto *compute_shader_derivatives_features =
907 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
908 if (compute_shader_derivatives_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600909 enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700910 }
locke-lunargd556cc32019-09-17 01:21:23 -0600911
sfricke-samsung828e59d2021-08-22 23:20:49 -0700912 const auto *fragment_shader_barycentric_features =
913 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
914 if (fragment_shader_barycentric_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600915 enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 }
locke-lunargd556cc32019-09-17 01:21:23 -0600917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *shader_image_footprint_features =
919 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
920 if (shader_image_footprint_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600921 enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700922 }
locke-lunargd556cc32019-09-17 01:21:23 -0600923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *fragment_shader_interlock_features =
925 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
926 if (fragment_shader_interlock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600927 enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 }
locke-lunargd556cc32019-09-17 01:21:23 -0600929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *texel_buffer_alignment_features =
931 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
932 if (texel_buffer_alignment_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600933 enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700934 }
locke-lunargd556cc32019-09-17 01:21:23 -0600935
sfricke-samsung828e59d2021-08-22 23:20:49 -0700936 const auto *pipeline_exe_props_features =
937 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
938 if (pipeline_exe_props_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600939 enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700940 }
locke-lunargd556cc32019-09-17 01:21:23 -0600941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *dedicated_allocation_image_aliasing_features =
943 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
944 if (dedicated_allocation_image_aliasing_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600945 enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500947
sfricke-samsung828e59d2021-08-22 23:20:49 -0700948 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
949 if (performance_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600950 enabled_features.performance_query_features = *performance_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700951 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100952
sfricke-samsung828e59d2021-08-22 23:20:49 -0700953 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
954 if (device_coherent_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600955 enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700956 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000957
sfricke-samsung828e59d2021-08-22 23:20:49 -0700958 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
959 if (ycbcr_image_array_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600960 enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700961 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800962
sfricke-samsung828e59d2021-08-22 23:20:49 -0700963 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
964 if (ray_query_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600965 enabled_features.ray_query_features = *ray_query_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700966 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700967
sfricke-samsung828e59d2021-08-22 23:20:49 -0700968 const auto *ray_tracing_pipeline_features =
969 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
970 if (ray_tracing_pipeline_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600971 enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700972 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700973
sfricke-samsung828e59d2021-08-22 23:20:49 -0700974 const auto *ray_tracing_acceleration_structure_features =
975 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
976 if (ray_tracing_acceleration_structure_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600977 enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
981 if (robustness2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600982 enabled_features.robustness2_features = *robustness2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700983 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500984
sfricke-samsung828e59d2021-08-22 23:20:49 -0700985 const auto *fragment_density_map_features =
986 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
987 if (fragment_density_map_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600988 enabled_features.fragment_density_map_features = *fragment_density_map_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 const auto *fragment_density_map_features2 =
992 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
993 if (fragment_density_map_features2) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600994 enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
sfricke-samsung828e59d2021-08-22 23:20:49 -0700995 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200996
Agarwal, Arpit78509112022-02-17 15:29:05 -0700997 const auto *fragment_density_map_offset_features =
998 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
999 if (fragment_density_map_offset_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001000 enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
Agarwal, Arpit78509112022-02-17 15:29:05 -07001001 }
1002
sfricke-samsung828e59d2021-08-22 23:20:49 -07001003 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1004 if (astc_decode_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001005 enabled_features.astc_decode_features = *astc_decode_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001006 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001007
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1009 if (custom_border_color_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001010 enabled_features.custom_border_color_features = *custom_border_color_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001011 }
Tony-LunarG7337b312020-04-15 16:40:25 -06001012
sfricke-samsung828e59d2021-08-22 23:20:49 -07001013 const auto *fragment_shading_rate_features =
1014 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1015 if (fragment_shading_rate_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001016 enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001017 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001018
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001019 const auto *fragment_shading_rate_enums_features =
1020 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
1021 if (fragment_shading_rate_enums_features) {
Jeremy Gebben217687e2022-04-04 08:44:16 -06001022 enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
sfricke-samsungc48c34f2022-03-23 00:24:21 -05001023 }
1024
sfricke-samsung828e59d2021-08-22 23:20:49 -07001025 const auto *extended_dynamic_state_features =
1026 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1027 if (extended_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001028 enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 }
Piers Daniell39842ee2020-07-10 16:42:33 -06001030
sfricke-samsung828e59d2021-08-22 23:20:49 -07001031 const auto *extended_dynamic_state2_features =
1032 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
1033 if (extended_dynamic_state2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001034 enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001035 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07001036
sfricke-samsung828e59d2021-08-22 23:20:49 -07001037 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1038 if (multiview_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001039 enabled_features.multiview_features = *multiview_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001040 }
locke-lunarg3fa463a2020-10-23 16:39:04 -06001041
sfricke-samsung828e59d2021-08-22 23:20:49 -07001042 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1043 if (portability_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001044 enabled_features.portability_subset_features = *portability_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001045 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001046
sfricke-samsung828e59d2021-08-22 23:20:49 -07001047 const auto *shader_integer_functions2_features =
1048 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1049 if (shader_integer_functions2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001050 enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001052
sfricke-samsung828e59d2021-08-22 23:20:49 -07001053 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1054 if (shader_sm_builtins_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001055 enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001056 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001057
sfricke-samsung828e59d2021-08-22 23:20:49 -07001058 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1059 if (shader_atomic_float_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001060 enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001061 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *shader_image_atomic_int64_features =
1064 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1065 if (shader_image_atomic_int64_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001066 enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001067 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001068
sfricke-samsung828e59d2021-08-22 23:20:49 -07001069 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1070 if (shader_clock_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001071 enabled_features.shader_clock_features = *shader_clock_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001072 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001073
sfricke-samsung828e59d2021-08-22 23:20:49 -07001074 const auto *conditional_rendering_features =
1075 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1076 if (conditional_rendering_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001077 enabled_features.conditional_rendering_features = *conditional_rendering_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001078 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001079
sfricke-samsung828e59d2021-08-22 23:20:49 -07001080 const auto *workgroup_memory_explicit_layout_features =
1081 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1082 if (workgroup_memory_explicit_layout_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001083 enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001084 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001085
sfricke-samsung828e59d2021-08-22 23:20:49 -07001086 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1087 if (provoking_vertex_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001088 enabled_features.provoking_vertex_features = *provoking_vertex_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001089 }
Locke Linf3873542021-04-26 11:25:10 -06001090
sfricke-samsung828e59d2021-08-22 23:20:49 -07001091 const auto *vertex_input_dynamic_state_features =
1092 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1093 if (vertex_input_dynamic_state_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001094 enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001095 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001096
sfricke-samsung828e59d2021-08-22 23:20:49 -07001097 const auto *inherited_viewport_scissor_features =
1098 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1099 if (inherited_viewport_scissor_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001100 enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001101 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001102
sfricke-samsung828e59d2021-08-22 23:20:49 -07001103 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1104 if (multi_draw_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001105 enabled_features.multi_draw_features = *multi_draw_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001106 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001107
sfricke-samsung828e59d2021-08-22 23:20:49 -07001108 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1109 if (color_write_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001110 enabled_features.color_write_features = *color_write_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001111 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001112
sfricke-samsung828e59d2021-08-22 23:20:49 -07001113 const auto *shader_atomic_float2_features =
1114 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1115 if (shader_atomic_float2_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001116 enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001117 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001118
sfricke-samsung828e59d2021-08-22 23:20:49 -07001119 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1120 if (present_id_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001121 enabled_features.present_id_features = *present_id_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001122 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001123
sfricke-samsung828e59d2021-08-22 23:20:49 -07001124 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1125 if (present_wait_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001126 enabled_features.present_wait_features = *present_wait_features;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001127 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001128
1129 const auto *ray_tracing_motion_blur_features =
1130 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1131 if (ray_tracing_motion_blur_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001132 enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001133 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001134
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001135 const auto *primitive_topology_list_restart_features =
1136 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1137 if (primitive_topology_list_restart_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001138 enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001139 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001140
ziga-lunarge1988962021-09-16 13:32:34 +02001141 const auto *zero_initialize_work_group_memory_features =
1142 LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR>(pCreateInfo->pNext);
1143 if (zero_initialize_work_group_memory_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001144 enabled_features.zero_initialize_work_group_memory_features = *zero_initialize_work_group_memory_features;
ziga-lunarge1988962021-09-16 13:32:34 +02001145 }
1146
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001147 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1148 if (rgba10x6_formats_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001149 enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001150 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001151
Tony-LunarG69604c42021-11-22 16:00:12 -07001152 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
1153 if (image_view_min_lod_features) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001154 enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
Tony-LunarG69604c42021-11-22 16:00:12 -07001155 }
ziga-lunarg8935ad12022-04-02 02:00:23 +02001156
1157 const auto *primitives_generated_query_features =
1158 LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
1159 if (primitives_generated_query_features) {
ziga-lunarg91649882022-04-05 12:37:50 +02001160 enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
ziga-lunarg8935ad12022-04-02 02:00:23 +02001161 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001162 }
1163
locke-lunargd556cc32019-09-17 01:21:23 -06001164 // Store physical device properties and physical device mem limits into CoreChecks structs
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001165 DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
1166 DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001167
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001168 {
1169 uint32_t n_props = 0;
1170 std::vector<VkExtensionProperties> props;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001171 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001172 props.resize(n_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001173 instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001174
1175 for (const auto &ext_prop : props) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001176 phys_dev_extensions.insert(ext_prop.extensionName);
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001177 }
1178
1179 // Even if VK_KHR_format_feature_flags2 is available, we need to have
1180 // a path to grab that information from the physical device. This
1181 // requires to have VK_KHR_get_physical_device_properties2 enabled or
1182 // Vulkan 1.1 (which made this core).
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001183 has_format_feature2 =
1184 (api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
1185 phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
Lionel Landwerlind0f84e42021-12-07 15:46:09 +02001186 }
1187
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001188 const auto &dev_ext = device_extensions;
1189 auto *phys_dev_props = &phys_dev_ext_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001190
Tony-LunarG273f32f2021-09-28 08:56:30 -06001191 // Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
1192 if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001193 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
1194 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
Tony-LunarG273f32f2021-09-28 08:56:30 -06001195 if (dev_ext.vk_feature_version_1_3)
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001196 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001197 } else {
1198 // VkPhysicalDeviceVulkan11Properties
1199 //
1200 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1201
1202 if (dev_ext.vk_khr_multiview) {
1203 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001204 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
1205 phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1206 phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001207 }
1208
1209 if (dev_ext.vk_khr_maintenance3) {
1210 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001211 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1212 phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1213 phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001214 }
1215
1216 // Some 1.1 properties were added to core without previous extensions
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001217 if (api_version >= VK_API_VERSION_1_1) {
sfricke-samsung828e59d2021-08-22 23:20:49 -07001218 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1219 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1220 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001221 instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001222
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001223 phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1224 phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1225 phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1226 phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001227
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001228 phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001229 }
1230
1231 // VkPhysicalDeviceVulkan12Properties
1232 //
1233 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1234
1235 if (dev_ext.vk_ext_descriptor_indexing) {
1236 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001237 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1238 phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001239 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001240 phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001241 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001242 phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001243 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001244 phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001245 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001246 phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001247 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001248 phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001249 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001250 phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1251 phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1252 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001253 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001254 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001255 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001256 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001257 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001258 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001259 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001260 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001261 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001262 phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001263 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001264 phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001265 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001266 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001267 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001268 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001269 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001270 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001271 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001272 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001273 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001274 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001275 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001276 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001277 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001278 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001279 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001280 phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001281 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1282 }
1283
1284 if (dev_ext.vk_khr_depth_stencil_resolve) {
1285 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001286 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1287 phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
1288 phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
1289 phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1290 phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001291 }
1292
1293 if (dev_ext.vk_khr_timeline_semaphore) {
1294 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001295 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1296 phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001297 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1298 }
1299
1300 if (dev_ext.vk_ext_sampler_filter_minmax) {
1301 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001302 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1303 phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001304 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001305 phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001306 }
1307
1308 if (dev_ext.vk_khr_shader_float_controls) {
1309 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001310 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1311 phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1312 phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1313 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001314 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001315 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001316 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001317 phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
sfricke-samsung828e59d2021-08-22 23:20:49 -07001318 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001319 phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1320 phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1321 phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1322 phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
1323 phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
1324 phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
1325 phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1326 phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1327 phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1328 phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1329 phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1330 phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
sfricke-samsung828e59d2021-08-22 23:20:49 -07001331 }
locke-lunargd556cc32019-09-17 01:21:23 -06001332 }
1333
sfricke-samsung828e59d2021-08-22 23:20:49 -07001334 // Extensions with properties to extract to DeviceExtensionProperties
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001335 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
1336 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1337 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1338 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
1339 &phys_dev_props->inline_uniform_block_props);
1340 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
1341 &phys_dev_props->vtx_attrib_divisor_props);
1342 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
1343 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
1344 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1345 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
1346 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
1347 &phys_dev_props->texel_buffer_alignment_props);
1348 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
1349 &phys_dev_props->fragment_density_map_props);
1350 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
1351 &phys_dev_props->fragment_density_map2_props);
1352 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
Agarwal, Arpit78509112022-02-17 15:29:05 -07001353 &phys_dev_props->fragment_density_map_offset_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001354 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
1355 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
1356 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
1357 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
1358 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
1359 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
1360 &phys_dev_props->fragment_shading_rate_props);
1361 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
1362 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
1363 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
1364 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
1365 &phys_dev_props->blend_operation_advanced_props);
1366 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
1367 &phys_dev_props->conservative_rasterization_props);
1368 GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
1369 &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001370
sfricke-samsung45996a42021-09-16 13:45:27 -07001371 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001372 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001373 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1374 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001375 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
1376 phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
locke-lunargd556cc32019-09-17 01:21:23 -06001377
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001378 uint32_t num_cooperative_matrix_properties = 0;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001379 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1380 NULL);
1381 cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001382
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001383 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
1384 cooperative_matrix_properties.data());
locke-lunargd556cc32019-09-17 01:21:23 -06001385 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001386
locke-lunargd556cc32019-09-17 01:21:23 -06001387 // Store queue family data
1388 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1389 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001390 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001391 queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1392 device_queue_info_list.push_back(
sfricke-samsungb585ec12021-05-06 03:10:13 -07001393 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001394 }
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001395 for (const auto &queue_info : device_queue_info_list) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001396 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1397 VkQueue queue = VK_NULL_HANDLE;
1398 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1399 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1400 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1401 get_info.flags = queue_info.flags;
1402 get_info.queueFamilyIndex = queue_info.queue_family_index;
1403 get_info.queueIndex = i;
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001404 DispatchGetDeviceQueue2(device, &get_info, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001405 } else {
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001406 DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001407 }
1408 assert(queue != VK_NULL_HANDLE);
Jeremy Gebben36a3b832022-03-23 10:54:18 -06001409 Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001410 }
locke-lunargd556cc32019-09-17 01:21:23 -06001411 }
1412 }
1413}
1414
1415void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1416 if (!device) return;
1417
Jeremy Gebbend177d922021-10-28 13:42:10 -06001418 command_pool_map_.clear();
1419 assert(command_buffer_map_.empty());
1420 pipeline_map_.clear();
1421 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001422
1423 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001424 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001425 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001426 assert(descriptor_set_map_.empty());
1427 desc_template_map_.clear();
1428 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001429 // Because swapchains are associated with Surfaces, which are at instance level,
1430 // they need to be explicitly destroyed here to avoid continued references to
1431 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001432 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001433 entry.second->Destroy();
1434 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001435 swapchain_map_.clear();
1436 image_view_map_.clear();
1437 image_map_.clear();
1438 buffer_view_map_.clear();
1439 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001440 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001441 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001442}
1443
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001444void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1445 VkFence fence, VkResult result) {
1446 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001447 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001448
Jeremy Gebben57642982021-09-14 14:14:55 -06001449 uint64_t early_retire_seq = 0;
1450
1451 if (submitCount == 0) {
1452 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001453 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001454 early_retire_seq = queue_state->Submit(std::move(submission));
1455 }
locke-lunargd556cc32019-09-17 01:21:23 -06001456
1457 // Now process each individual submit
1458 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001459 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001460 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001461 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001462 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001463 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001464 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1465 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1466 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1467 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001468 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001469 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001470
locke-lunargd556cc32019-09-17 01:21:23 -06001471 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001472 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001473 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1474 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1475 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1476 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001477 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001478 }
1479
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001480 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001481 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001482
locke-lunargd556cc32019-09-17 01:21:23 -06001483 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Tony-LunarG3e8f3e42022-04-01 11:03:45 -06001484 auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
1485 if (cb_state) {
1486 submission.AddCommandBuffer(std::move(cb_state));
1487 }
locke-lunargd556cc32019-09-17 01:21:23 -06001488 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001489 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001490 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001491 }
1492 auto submit_seq = queue_state->Submit(std::move(submission));
1493 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001494 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001495
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001496 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001497 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001498 }
1499}
1500
Tony-LunarG26fe2842021-11-16 14:07:59 -07001501void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1502 VkFence fence, VkResult result) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001503 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001504 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001505 uint64_t early_retire_seq = 0;
1506 if (submitCount == 0) {
1507 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001508 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001509 early_retire_seq = queue_state->Submit(std::move(submission));
1510 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001511
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001512 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1513 CB_SUBMISSION submission;
1514 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001515 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1516 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001517 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001518 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001519 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1520 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001521 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001522 }
1523 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1524 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1525
1526 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001527 submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001528 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001529 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001530 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001531 }
1532 auto submit_seq = queue_state->Submit(std::move(submission));
1533 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001534 }
locke-lunargd556cc32019-09-17 01:21:23 -06001535 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001536 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001537 }
1538}
1539
Tony-LunarG26fe2842021-11-16 14:07:59 -07001540void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1541 VkFence fence, VkResult result) {
1542 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1543}
1544
1545void ValidationStateTracker::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
1546 VkFence fence, VkResult result) {
1547 RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result);
1548}
1549
locke-lunargd556cc32019-09-17 01:21:23 -06001550void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1551 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1552 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001553 if (VK_SUCCESS != result) {
1554 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001555 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001556 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1557 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1558 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1559
1560 layer_data::optional<DedicatedBinding> dedicated_binding;
1561
1562 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1563 if (dedicated) {
1564 if (dedicated->buffer) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001565 auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001566 assert(buffer_state);
1567 if (!buffer_state) {
1568 return;
1569 }
1570 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1571 } else if (dedicated->image) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001572 auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001573 assert(image_state);
1574 if (!image_state) {
1575 return;
1576 }
1577 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1578 }
1579 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001580 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1581 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001582 return;
1583}
1584
1585void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001586 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001587 if (mem_info) {
1588 fake_memory.Free(mem_info->fake_base_address);
1589 }
1590 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001591}
1592
1593void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1594 VkFence fence, VkResult result) {
1595 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001596 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001597
Jeremy Gebben57642982021-09-14 14:14:55 -06001598 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001599
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001600 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1601 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001602 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001603 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1604 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1605 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001606 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001607 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001608 if (buffer_state && mem_state) {
1609 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1610 }
locke-lunargd556cc32019-09-17 01:21:23 -06001611 }
1612 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001613 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1614 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1615 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001616 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001617 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001618 if (image_state && mem_state) {
1619 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1620 }
locke-lunargd556cc32019-09-17 01:21:23 -06001621 }
1622 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001623 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1624 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1625 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001626 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1627 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001628 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001629 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001630 if (image_state && mem_state) {
1631 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1632 }
locke-lunargd556cc32019-09-17 01:21:23 -06001633 }
1634 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001635 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001636 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001637 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001638 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001639 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001640 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001641 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001642 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001643 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001644 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001645 auto submit_seq = queue_state->Submit(std::move(submission));
1646 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001647 }
1648
1649 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001650 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001651 }
1652}
1653
1654void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1655 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1656 VkResult result) {
1657 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001658 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001659}
1660
Mike Schuchardt2df08912020-12-15 16:28:09 -08001661void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1662 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001663 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1664 if (semaphore_state) {
1665 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001666 }
1667}
1668
Mike Schuchardt2df08912020-12-15 16:28:09 -08001669void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001670 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001671 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001672 if (semaphore_state) {
1673 semaphore_state->RetireTimeline(pSignalInfo->value);
1674 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001675}
1676
locke-lunargd556cc32019-09-17 01:21:23 -06001677void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001678 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001679 if (mem_info) {
1680 mem_info->mapped_range.offset = offset;
1681 mem_info->mapped_range.size = size;
1682 mem_info->p_driver_data = *ppData;
1683 }
1684}
1685
locke-lunargd556cc32019-09-17 01:21:23 -06001686void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1687 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1688 if (VK_SUCCESS != result) return;
1689
1690 // When we know that all fences are complete we can clean/remove their CBs
1691 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1692 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001693 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001694 if (fence_state) {
1695 fence_state->Retire();
1696 }
locke-lunargd556cc32019-09-17 01:21:23 -06001697 }
1698 }
1699 // NOTE : Alternate case not handled here is when some fences have completed. In
1700 // this case for app to guarantee which fences completed it will have to call
1701 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1702}
1703
John Zulauff89de662020-04-13 18:57:34 -06001704void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1705 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001706 if (VK_SUCCESS != result) return;
1707
Jeremy Gebben15332642021-12-15 19:33:15 -07001708 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1709 // the application calls vkGetSemaphoreCounterValue() on each of them.
1710 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1711 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1712 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1713 if (semaphore_state) {
1714 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1715 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001716 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001717 }
1718}
1719
John Zulauff89de662020-04-13 18:57:34 -06001720void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1721 VkResult result) {
1722 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1723}
1724
1725void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1726 uint64_t timeout, VkResult result) {
1727 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1728}
1729
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001730void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1731 VkResult result) {
1732 if (VK_SUCCESS != result) return;
1733
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001734 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001735 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001736 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001737 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001738}
1739
1740void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1741 VkResult result) {
1742 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1743}
1744void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1745 VkResult result) {
1746 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1747}
1748
locke-lunargd556cc32019-09-17 01:21:23 -06001749void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1750 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001751 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001752 if (fence_state) {
1753 fence_state->Retire();
1754 }
locke-lunargd556cc32019-09-17 01:21:23 -06001755}
1756
Yilong Lice03a312022-01-02 02:08:35 -08001757void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1758 if (Get<QUEUE_STATE>(queue) == nullptr) {
1759 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1760 }
1761}
1762
1763void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1764 VkQueue *pQueue) {
1765 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1766}
1767
1768void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1769 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1770}
1771
locke-lunargd556cc32019-09-17 01:21:23 -06001772void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1773 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001774 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001775 if (queue_state) {
1776 queue_state->Retire();
1777 }
locke-lunargd556cc32019-09-17 01:21:23 -06001778}
1779
1780void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1781 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001782 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001783 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001784 }
1785}
1786
1787void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001788 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001789}
1790
1791void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1792 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001793 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001794}
1795
1796void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001797 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001798}
1799
1800void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1801 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001802 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001803}
1804
locke-lunargd556cc32019-09-17 01:21:23 -06001805void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001806 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001807 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001808 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001809 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001810 if (mem_state) {
1811 buffer_state->SetMemBinding(mem_state, memoryOffset);
1812 }
locke-lunargd556cc32019-09-17 01:21:23 -06001813 }
1814}
1815
1816void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1817 VkDeviceSize memoryOffset, VkResult result) {
1818 if (VK_SUCCESS != result) return;
1819 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1820}
1821
1822void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001823 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001824 for (uint32_t i = 0; i < bindInfoCount; i++) {
1825 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1826 }
1827}
1828
1829void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001830 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001831 for (uint32_t i = 0; i < bindInfoCount; i++) {
1832 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1833 }
1834}
1835
Spencer Fricke6c127102020-04-16 06:25:20 -07001836void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001837 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001838 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001839 buffer_state->memory_requirements_checked = true;
1840 }
1841}
1842
1843void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1844 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001845 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001846}
1847
1848void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001849 const VkBufferMemoryRequirementsInfo2 *pInfo,
1850 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001851 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001852}
1853
1854void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001855 const VkBufferMemoryRequirementsInfo2 *pInfo,
1856 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001857 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001858}
1859
Spencer Fricke6c127102020-04-16 06:25:20 -07001860void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001861 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001862 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001863 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001864 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001865 if (plane_info != nullptr) {
1866 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001867 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001868 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001869 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001870 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001871 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001872 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001873 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001874 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001875 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001876 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001877 }
locke-lunargd556cc32019-09-17 01:21:23 -06001878 }
1879}
1880
1881void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1882 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001883 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001884}
1885
1886void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1887 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001888 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001889}
1890
1891void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1892 const VkImageMemoryRequirementsInfo2 *pInfo,
1893 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001894 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001895}
1896
locke-lunargd556cc32019-09-17 01:21:23 -06001897void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1898 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1899 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001900 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001901 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001902}
1903
1904void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001905 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1906 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001907 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001908 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001909}
1910
1911void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001912 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1913 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001914 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001915 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001916}
1917
1918void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1919 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001920 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001921}
1922
1923void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1924 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001925 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001926}
1927
1928void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1929 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001930 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001931}
1932
1933void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1934 const VkAllocationCallbacks *pAllocator) {
1935 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001936 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001937 // Any bound cmd buffers are now invalid
1938 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001939 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1940 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1941 custom_border_color_sampler_count--;
1942 }
locke-lunargd556cc32019-09-17 01:21:23 -06001943 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001944 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001945}
1946
1947void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1948 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001949 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001950}
1951
1952void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1953 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001954 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001955}
1956
locke-lunargd556cc32019-09-17 01:21:23 -06001957void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1958 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001959 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1960 if (pool) {
1961 pool->Free(commandBufferCount, pCommandBuffers);
1962 }
locke-lunargd556cc32019-09-17 01:21:23 -06001963}
1964
1965void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1966 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1967 VkResult result) {
1968 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001969 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001970 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001971}
1972
1973void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1974 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1975 VkResult result) {
1976 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001977
1978 uint32_t index_count = 0, n_perf_pass = 0;
1979 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001980 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001981 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001982 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001983
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001984 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001985 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1986 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1987 switch (counter.scope) {
1988 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001989 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001990 break;
1991 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001992 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001993 break;
1994 default:
1995 break;
1996 }
1997 }
1998
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001999 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002000 }
2001
Jeremy Gebben082a9832021-10-28 13:40:11 -06002002 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 -06002003
locke-lunargd556cc32019-09-17 01:21:23 -06002004}
2005
2006void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2007 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002008 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002009}
2010
2011void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2012 VkCommandPoolResetFlags flags, VkResult result) {
2013 if (VK_SUCCESS != result) return;
2014 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002015 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
2016 if (pool) {
2017 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002018 }
2019}
2020
2021void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2022 VkResult result) {
2023 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002024 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002025 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002026 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002027 }
2028 }
2029}
2030
locke-lunargd556cc32019-09-17 01:21:23 -06002031void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2032 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002033 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002034}
2035
2036void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2037 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002038 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2042 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2043 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002044 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002045}
2046
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002047std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
2048 const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
2049 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2050 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout));
2051}
2052
locke-lunargd556cc32019-09-17 01:21:23 -06002053bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2054 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2055 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002056 void *cgpl_state_data) const {
ziga-lunarg08c81582022-03-08 17:33:45 +01002057 bool skip = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002058 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2059 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2060 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2061 cgpl_state->pipe_state.reserve(count);
2062 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002063 const auto &create_info = pCreateInfos[i];
2064 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
2065 std::shared_ptr<const RENDER_PASS_STATE> render_pass;
2066
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002067 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002068 render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
Tony-LunarG273f32f2021-09-28 08:56:30 -06002069 } else if (enabled_features.core13.dynamicRendering) {
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002070 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
2071 render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
ziga-lunarg08c81582022-03-08 17:33:45 +01002072 } else {
ziga-lunarg08c81582022-03-08 17:33:45 +01002073 skip = true;
Jeremy Gebbence23dac2021-11-10 10:19:42 -07002074 }
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002075 cgpl_state->pipe_state.push_back(
2076 CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state)));
locke-lunargd556cc32019-09-17 01:21:23 -06002077 }
ziga-lunarg08c81582022-03-08 17:33:45 +01002078 return skip;
locke-lunargd556cc32019-09-17 01:21:23 -06002079}
2080
2081void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2082 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2083 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2084 VkResult result, void *cgpl_state_data) {
2085 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2086 // This API may create pipelines regardless of the return value
2087 for (uint32_t i = 0; i < count; i++) {
2088 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002089 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002090 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002091 }
2092 }
2093 cgpl_state->pipe_state.clear();
2094}
2095
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002096std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
2097 const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2098 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2099}
2100
locke-lunargd556cc32019-09-17 01:21:23 -06002101bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2102 const VkComputePipelineCreateInfo *pCreateInfos,
2103 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002104 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002105 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2106 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2107 ccpl_state->pipe_state.reserve(count);
2108 for (uint32_t i = 0; i < count; i++) {
2109 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002110 ccpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002111 CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002112 }
2113 return false;
2114}
2115
2116void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2117 const VkComputePipelineCreateInfo *pCreateInfos,
2118 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2119 VkResult result, void *ccpl_state_data) {
2120 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2121
2122 // This API may create pipelines regardless of the return value
2123 for (uint32_t i = 0; i < count; i++) {
2124 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002125 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002126 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002127 }
2128 }
2129 ccpl_state->pipe_state.clear();
2130}
2131
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002132std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2133 const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2134 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2135}
2136
locke-lunargd556cc32019-09-17 01:21:23 -06002137bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2138 uint32_t count,
2139 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2140 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002141 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002142 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2143 crtpl_state->pipe_state.reserve(count);
2144 for (uint32_t i = 0; i < count; i++) {
2145 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002146 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002147 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002148 }
2149 return false;
2150}
2151
2152void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2153 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2154 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2155 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2156 // This API may create pipelines regardless of the return value
2157 for (uint32_t i = 0; i < count; i++) {
2158 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002159 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06002160 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06002161 }
2162 }
2163 crtpl_state->pipe_state.clear();
2164}
2165
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002166std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
2167 const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
2168 return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
2169}
2170
sourav parmarcd5fb182020-07-17 12:58:44 -07002171bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2172 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002173 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2174 const VkAllocationCallbacks *pAllocator,
2175 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002176 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002177 crtpl_state->pipe_state.reserve(count);
2178 for (uint32_t i = 0; i < count; i++) {
2179 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002180 crtpl_state->pipe_state.push_back(
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002181 CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002182 }
2183 return false;
2184}
2185
sourav parmarcd5fb182020-07-17 12:58:44 -07002186void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2187 VkPipelineCache pipelineCache, uint32_t count,
2188 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2189 const VkAllocationCallbacks *pAllocator,
2190 VkPipeline *pPipelines, VkResult result,
2191 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002192 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
aitor-lunarg3c145292022-03-25 17:30:11 +01002193 bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002194 // This API may create pipelines regardless of the return value
aitor-lunarg3c145292022-03-25 17:30:11 +01002195
2196 if (!operation_is_deferred) {
2197 for (uint32_t i = 0; i < count; i++) {
2198 if (pPipelines[i] != VK_NULL_HANDLE) {
2199 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
2200 Add(std::move((crtpl_state->pipe_state)[i]));
2201 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002202 }
aitor-lunarg3c145292022-03-25 17:30:11 +01002203 } else {
2204 auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2205 if (wrap_handles) {
2206 deferredOperation = layer_data->Unwrap(deferredOperation);
2207 }
2208 std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
2209 auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
2210 if (find_res->first) {
2211 cleanup_fn = std::move(find_res->second);
2212 }
2213 auto &pipeline_states = crtpl_state->pipe_state;
2214 // Mutable lambda because we want to move the shared pointer contained in the copied vector
2215 cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
2216 for (size_t i = 0; i < pipeline_states.size(); ++i) {
2217 pipeline_states[i]->SetHandle(pipelines[i]);
2218 this->Add(std::move(pipeline_states[i]));
2219 }
2220 });
2221 layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002222 }
2223 crtpl_state->pipe_state.clear();
2224}
2225
locke-lunargd556cc32019-09-17 01:21:23 -06002226void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2227 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2228 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002229 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002230 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2231 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002232 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002233 }
locke-lunargd556cc32019-09-17 01:21:23 -06002234}
2235
2236void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2237 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2238 const VkAllocationCallbacks *pAllocator,
2239 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2240 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002241 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06002242}
2243
locke-lunargd556cc32019-09-17 01:21:23 -06002244void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2245 const VkAllocationCallbacks *pAllocator,
2246 VkPipelineLayout *pPipelineLayout, VkResult result) {
2247 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002248 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002249}
2250
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002251std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
2252 VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
2253 return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
2254}
2255
locke-lunargd556cc32019-09-17 01:21:23 -06002256void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2257 const VkAllocationCallbacks *pAllocator,
2258 VkDescriptorPool *pDescriptorPool, VkResult result) {
2259 if (VK_SUCCESS != result) return;
Jeremy Gebben20da7a12022-02-25 14:07:46 -07002260 Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002261}
2262
2263void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2264 VkDescriptorPoolResetFlags flags, VkResult result) {
2265 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002266 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2267 if (pool) {
2268 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002269 }
locke-lunargd556cc32019-09-17 01:21:23 -06002270}
2271
2272bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2273 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002274 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002275 // Always update common data
2276 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2277 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2278 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2279
2280 return false;
2281}
2282
2283// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2284void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2285 VkDescriptorSet *pDescriptorSets, VkResult result,
2286 void *ads_state_data) {
2287 if (VK_SUCCESS != result) return;
2288 // All the updates are contained in a single cvdescriptorset function
2289 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2290 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002291 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2292 if (pool_state) {
2293 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2294 }
locke-lunargd556cc32019-09-17 01:21:23 -06002295}
2296
2297void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2298 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002299 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2300 if (pool_state) {
2301 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002302 }
2303}
2304
2305void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2306 const VkWriteDescriptorSet *pDescriptorWrites,
2307 uint32_t descriptorCopyCount,
2308 const VkCopyDescriptorSet *pDescriptorCopies) {
2309 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2310 pDescriptorCopies);
2311}
2312
2313void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002314 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002315 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002316 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002317 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002318 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002319 }
2320}
2321
locke-lunargd556cc32019-09-17 01:21:23 -06002322void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2323 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002324 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002325 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002326
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002327 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002328}
2329
2330void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002331 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002332 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002333
2334 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002335}
2336
2337void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2338 VkResult result) {
2339 if (VK_SUCCESS == result) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002340 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2341 if (cb_state) {
2342 cb_state->Reset();
2343 }
locke-lunargd556cc32019-09-17 01:21:23 -06002344 }
2345}
2346
2347CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2348 // initially assume everything is static state
2349 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2350
2351 if (ds) {
2352 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002353 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002354 }
2355 }
locke-lunargd556cc32019-09-17 01:21:23 -06002356 return flags;
2357}
2358
2359// Validation cache:
2360// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002361
2362void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2363 VkPipeline pipeline) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002364 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002365 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002366 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002367
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002368 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002369 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002370 const auto &create_info = pipe_state->create_info.graphics;
2371 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2372 const auto *viewport_state = create_info.pViewportState;
2373 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002374 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002375 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002376 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002377 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002378
2379 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002380 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2381 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002382 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002383 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002384 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002385 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002386 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002387 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002388
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002389 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002390 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2391 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2392 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002393 if (!has_dynamic_viewport_count) {
2394 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002395 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002396 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2397 // should become = ~uint32_t(0) if the other interpretation is correct.
2398 }
2399 }
2400 if (!has_dynamic_scissor_count) {
2401 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002402 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002403 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2404 // should become = ~uint32_t(0) if the other interpretation is correct.
2405 }
2406 }
locke-lunargd556cc32019-09-17 01:21:23 -06002407 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002408 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002409 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002410 if (!disabled[command_buffer_state]) {
2411 cb_state->AddChild(pipe_state);
2412 }
locke-lunargd556cc32019-09-17 01:21:23 -06002413}
2414
2415void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2416 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002417 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002418 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002419 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2420 cb_state->viewportMask |= bits;
2421 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002422
2423 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2424 for (size_t i = 0; i < viewportCount; ++i) {
2425 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2426 }
locke-lunargd556cc32019-09-17 01:21:23 -06002427}
2428
2429void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2430 uint32_t exclusiveScissorCount,
2431 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002432 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002433 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002434 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2435 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002436}
2437
2438void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2439 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002440 if (disabled[command_buffer_state]) return;
2441
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002442 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002443 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002444
2445 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002446 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002447 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002448 }
2449}
2450
2451void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2452 uint32_t viewportCount,
2453 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002454 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002455 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002456 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2457 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002458}
2459
2460void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2461 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2462 const VkAllocationCallbacks *pAllocator,
2463 VkAccelerationStructureNV *pAccelerationStructure,
2464 VkResult result) {
2465 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002466 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE>(device, *pAccelerationStructure, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002467}
2468
Jeff Bolz95176d02020-04-01 00:36:16 -05002469void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2470 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2471 const VkAllocationCallbacks *pAllocator,
2472 VkAccelerationStructureKHR *pAccelerationStructure,
2473 VkResult result) {
2474 if (VK_SUCCESS != result) return;
Jeremy Gebbenfca381c2022-02-17 14:29:55 -07002475 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
2476 Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
Jeff Bolz95176d02020-04-01 00:36:16 -05002477}
2478
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002479void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2480 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2481 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2482 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2483 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002484 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002485 if (dst_as_state != nullptr) {
2486 dst_as_state->Build(&pInfos[i]);
2487 }
2488 }
2489}
2490
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002491// helper method for device side acceleration structure builds
2492void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
2493 const VkAccelerationStructureBuildGeometryInfoKHR &info) {
2494 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
2495 if (dst_as_state) {
2496 dst_as_state->Build(&info);
2497 }
2498 if (disabled[command_buffer_state]) {
2499 return;
2500 }
2501 if (dst_as_state) {
2502 cb_state.AddChild(dst_as_state);
2503 }
2504 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
2505 if (src_as_state) {
2506 cb_state.AddChild(src_as_state);
2507 }
2508 auto scratch_buffer = GetBufferByAddress(info.scratchData.deviceAddress);
2509 if (scratch_buffer) {
2510 cb_state.AddChild(scratch_buffer);
2511 }
2512
2513 for (uint32_t i = 0; i < info.geometryCount; i++) {
2514 // only one of pGeometries and ppGeometries can be non-null
2515 const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
2516 switch (geom.geometryType) {
2517 case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
2518 auto vertex_buffer = GetBufferByAddress(geom.geometry.triangles.vertexData.deviceAddress);
2519 if (vertex_buffer) {
2520 cb_state.AddChild(vertex_buffer);
2521 }
2522 auto index_buffer = GetBufferByAddress(geom.geometry.triangles.indexData.deviceAddress);
2523 if (index_buffer) {
2524 cb_state.AddChild(index_buffer);
2525 }
2526 auto transform_buffer = GetBufferByAddress(geom.geometry.triangles.transformData.deviceAddress);
2527 if (transform_buffer) {
2528 cb_state.AddChild(transform_buffer);
2529 }
2530 const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
2531 if (motion_data) {
2532 auto motion_buffer = GetBufferByAddress(motion_data->vertexData.deviceAddress);
2533 if (motion_buffer) {
2534 cb_state.AddChild(motion_buffer);
2535 }
2536 }
2537 } break;
2538 case VK_GEOMETRY_TYPE_AABBS_KHR: {
2539 auto data_buffer = GetBufferByAddress(geom.geometry.aabbs.data.deviceAddress);
2540 if (data_buffer) {
2541 cb_state.AddChild(data_buffer);
2542 }
2543 } break;
2544 case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
2545 // NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
2546 // require that data buffer be mapped to the CPU so that we could walk through it. We can't
2547 // easily ensure that's true.
2548 auto data_buffer = GetBufferByAddress(geom.geometry.instances.data.deviceAddress);
2549 if (data_buffer) {
2550 cb_state.AddChild(data_buffer);
2551 }
2552 } break;
2553 default:
2554 break;
2555 }
2556 }
2557}
2558
sourav parmarcd5fb182020-07-17 12:58:44 -07002559void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2560 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2561 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002562 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002563 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002564 return;
2565 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002566 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002567 for (uint32_t i = 0; i < infoCount; i++) {
2568 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
sourav parmarcd5fb182020-07-17 12:58:44 -07002569 }
2570 cb_state->hasBuildAccelerationStructureCmd = true;
2571}
2572
2573void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2574 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2575 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2576 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002577 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2578 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002579 return;
2580 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002581 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002582 for (uint32_t i = 0; i < infoCount; i++) {
2583 RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002584 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002585 auto indirect_buffer = GetBufferByAddress(pIndirectDeviceAddresses[i]);
2586 if (indirect_buffer) {
2587 cb_state->AddChild(indirect_buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002588 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002589 }
2590 }
2591 cb_state->hasBuildAccelerationStructureCmd = true;
2592}
Jeremy Gebbenc1063462022-02-11 09:31:18 -07002593
locke-lunargd556cc32019-09-17 01:21:23 -06002594void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002595 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002596 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002597 if (as_state != nullptr) {
2598 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002599 as_state->memory_requirements_checked = true;
2600 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002601 as_state->build_scratch_memory_requirements_checked = true;
2602 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
locke-lunargd556cc32019-09-17 01:21:23 -06002603 as_state->update_scratch_memory_requirements_checked = true;
2604 }
2605 }
2606}
2607
sourav parmarcd5fb182020-07-17 12:58:44 -07002608void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2609 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002610 if (VK_SUCCESS != result) return;
2611 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002612 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002613
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002614 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002615 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002616 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002617 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002618 if (mem_state) {
2619 as_state->SetMemBinding(mem_state, info.memoryOffset);
2620 }
locke-lunargd556cc32019-09-17 01:21:23 -06002621
2622 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002623 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002624 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002625 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2626 }
2627 }
2628 }
2629}
2630
2631void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2632 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2633 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002634 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2635 if (!cb_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002636 return;
2637 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002638 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002639
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002640 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002641 if (dst_as_state) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002642 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002643 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002644 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002645 }
locke-lunargd556cc32019-09-17 01:21:23 -06002646 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002647 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002648 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002649 if (src_as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002650 cb_state->AddChild(src_as_state);
2651 }
Jeremy Gebben81ed7672022-02-22 10:56:04 -07002652 auto instance_buffer = Get<BUFFER_STATE>(instanceData);
2653 if (instance_buffer) {
2654 cb_state->AddChild(instance_buffer);
2655 }
2656 auto scratch_buffer = Get<BUFFER_STATE>(scratch);
2657 if (scratch_buffer) {
2658 cb_state->AddChild(scratch_buffer);
2659 }
2660
2661 for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
2662 const auto& geom = pInfo->pGeometries[i];
2663
2664 auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
2665 if (vertex_buffer) {
2666 cb_state->AddChild(vertex_buffer);
2667 }
2668 auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
2669 if (index_buffer) {
2670 cb_state->AddChild(index_buffer);
2671 }
2672 auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
2673 if (transform_buffer) {
2674 cb_state->AddChild(transform_buffer);
2675 }
2676
2677 auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
2678 if (aabb_buffer) {
2679 cb_state->AddChild(aabb_buffer);
2680 }
2681 }
2682
locke-lunargd556cc32019-09-17 01:21:23 -06002683 }
2684 cb_state->hasBuildAccelerationStructureCmd = true;
2685}
2686
2687void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2688 VkAccelerationStructureNV dst,
2689 VkAccelerationStructureNV src,
2690 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002691 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002692 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002693 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2694 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002695 if (!disabled[command_buffer_state]) {
2696 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2697 }
locke-lunargd556cc32019-09-17 01:21:23 -06002698 if (dst_as_state != nullptr && src_as_state != nullptr) {
2699 dst_as_state->built = true;
2700 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002701 }
2702 }
2703}
2704
Jeff Bolz95176d02020-04-01 00:36:16 -05002705void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2706 VkAccelerationStructureKHR accelerationStructure,
2707 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002708 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002709}
2710
Jeff Bolz95176d02020-04-01 00:36:16 -05002711void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2712 VkAccelerationStructureNV accelerationStructure,
2713 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002714 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002715}
2716
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002717void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2718 uint32_t viewportCount,
2719 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002720 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002721 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002722}
2723
locke-lunargd556cc32019-09-17 01:21:23 -06002724void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
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_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002727}
2728
2729void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2730 uint16_t lineStipplePattern) {
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_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002733}
2734
2735void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2736 float depthBiasClamp, float depthBiasSlopeFactor) {
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_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002739}
2740
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002741void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2742 const VkRect2D *pScissors) {
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_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002745 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2746 cb_state->scissorMask |= bits;
2747 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002748}
2749
locke-lunargd556cc32019-09-17 01:21:23 -06002750void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002751 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002752 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002753}
2754
2755void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2756 float maxDepthBounds) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002757 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002758 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002759}
2760
2761void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2762 uint32_t compareMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002763 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002764 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002765}
2766
2767void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2768 uint32_t writeMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002769 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002770 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002771}
2772
2773void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2774 uint32_t reference) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002775 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002776 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002777}
2778
locke-lunargd556cc32019-09-17 01:21:23 -06002779// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2780void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2781 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2782 uint32_t firstSet, uint32_t setCount,
2783 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2784 const uint32_t *pDynamicOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002785 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002786 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002787 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002788 std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
locke-lunargd556cc32019-09-17 01:21:23 -06002789
Jeremy Gebben4d51c552022-01-06 21:27:15 -07002790 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets,
2791 no_push_desc, dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002792}
2793
locke-lunargd556cc32019-09-17 01:21:23 -06002794void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2795 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2796 uint32_t set, uint32_t descriptorWriteCount,
2797 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002798 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002799 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002800 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002801}
2802
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002803void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2804 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2805 const void *pValues) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002806 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2807 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002808 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002809 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2810 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002811
2812 auto &push_constant_data = cb_state->push_constant_data;
2813 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2814 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002815 cb_state->push_constant_pipeline_layout_set = layout;
2816
2817 auto flags = stageFlags;
2818 uint32_t bit_shift = 0;
2819 while (flags) {
2820 if (flags & 1) {
2821 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2822 const auto it = cb_state->push_constant_data_update.find(flag);
2823
2824 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002825 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002826 }
2827 }
2828 flags = flags >> 1;
2829 ++bit_shift;
2830 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002831 }
2832}
2833
locke-lunargd556cc32019-09-17 01:21:23 -06002834void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2835 VkIndexType indexType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002836 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002837
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002838 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002839 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002840 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002841 cb_state->index_buffer_binding.offset = offset;
2842 cb_state->index_buffer_binding.index_type = indexType;
2843 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002844 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002845 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002846 }
locke-lunargd556cc32019-09-17 01:21:23 -06002847}
2848
2849void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2850 uint32_t bindingCount, const VkBuffer *pBuffers,
2851 const VkDeviceSize *pOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002852 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002853 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002854
2855 uint32_t end = firstBinding + bindingCount;
2856 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2857 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2858 }
2859
2860 for (uint32_t i = 0; i < bindingCount; ++i) {
2861 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002862 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002863 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002864 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2865 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002866 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002867 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002868 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002869 }
locke-lunargd556cc32019-09-17 01:21:23 -06002870 }
2871}
2872
2873void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2874 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002875 if (disabled[command_buffer_state]) return;
2876
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002877 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002878 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002879}
2880
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002881void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2882 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002883 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002884 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002885}
2886
2887void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2888 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002889 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002890 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2891
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002892 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2893 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002894}
2895
Tony-LunarGc43525f2021-11-15 16:12:38 -07002896void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2897 const VkDependencyInfo* pDependencyInfo) {
2898 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2899 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2900
2901 cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
2902 cb_state->RecordBarriers(*pDependencyInfo);
2903}
2904
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002905void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2906 VkPipelineStageFlags stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002907 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002908 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002909}
2910
2911void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2912 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002913 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002914 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002915}
2916
Tony-LunarGa2662db2021-11-16 07:26:24 -07002917void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
2918 VkPipelineStageFlags2 stageMask) {
2919 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2920 cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
2921}
2922
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002923void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2924 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2925 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2926 uint32_t bufferMemoryBarrierCount,
2927 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2928 uint32_t imageMemoryBarrierCount,
2929 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002930 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2931 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002932 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2933 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002934}
2935
2936void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2937 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002938 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben79649152021-06-22 14:46:24 -06002939 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002940 const auto &dep_info = pDependencyInfos[i];
2941 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2942 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
2943 cb_state->RecordBarriers(dep_info);
Jeremy Gebben79649152021-06-22 14:46:24 -06002944 }
2945}
2946
Tony-LunarG1364cf52021-11-17 16:10:11 -07002947void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2948 const VkDependencyInfo *pDependencyInfos) {
2949 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2950 for (uint32_t i = 0; i < eventCount; i++) {
2951 const auto &dep_info = pDependencyInfos[i];
2952 auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
2953 cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
2954 cb_state->RecordBarriers(dep_info);
2955 }
2956}
2957
Jeremy Gebben79649152021-06-22 14:46:24 -06002958void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2959 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2960 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2961 uint32_t bufferMemoryBarrierCount,
2962 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2963 uint32_t imageMemoryBarrierCount,
2964 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002965 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002966 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2967 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2968 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002969}
2970
2971void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2972 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002973 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002974 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2975 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002976}
2977
Tony-LunarG3f6eceb2021-11-18 14:34:49 -07002978void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
2979 const VkDependencyInfo *pDependencyInfo) {
2980 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
2981 cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
2982 cb_state->RecordBarriers(*pDependencyInfo);
2983}
2984
locke-lunargd556cc32019-09-17 01:21:23 -06002985void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2986 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002987 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002988
locke-lunargd556cc32019-09-17 01:21:23 -06002989 QueryObject query = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07002990 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002991 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002992 if (!disabled[query_validation]) {
2993 cb_state->BeginQuery(query);
2994 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002995 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002996 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002997 cb_state->AddChild(pool_state);
2998 }
locke-lunargd556cc32019-09-17 01:21:23 -06002999}
3000
3001void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003002 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003003 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003004 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003005 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003006 if (!disabled[query_validation]) {
3007 cb_state->EndQuery(query_obj);
3008 }
3009 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003010 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003011 cb_state->AddChild(pool_state);
3012 }
locke-lunargd556cc32019-09-17 01:21:23 -06003013}
3014
3015void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3016 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003017 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003018 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003019
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003020 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003021 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003022
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003023 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003024 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003025 cb_state->AddChild(pool_state);
3026 }
locke-lunargd556cc32019-09-17 01:21:23 -06003027}
3028
3029void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3030 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3031 VkDeviceSize dstOffset, VkDeviceSize stride,
3032 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003033 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3034
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003035 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003036 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003037 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003038 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003039 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003040 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003041}
3042
3043void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3044 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003045 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003046 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003047}
3048
3049void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3050 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3051 uint32_t slot) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003052 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003053 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003054}
3055
Tony-LunarGde9936b2021-11-17 15:34:11 -07003056void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
3057 VkQueryPool queryPool, uint32_t slot) {
3058 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3059 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
3060}
3061
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003062void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3063 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3064 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3065 if (disabled[query_validation]) return;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003066 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003067 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003068 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003069 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003070 cb_state->AddChild(pool_state);
3071 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003072 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003073}
3074
locke-lunargd556cc32019-09-17 01:21:23 -06003075void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3076 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3077 VkResult result) {
3078 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003079
Jeremy Gebben88f58142021-06-01 10:07:52 -06003080 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003081 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003082 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003083
locke-lunargd556cc32019-09-17 01:21:23 -06003084 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003085 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003086 }
3087 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003088
Jeremy Gebben9f537102021-10-05 16:37:12 -06003089 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06003090 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06003091}
3092
locke-lunargd556cc32019-09-17 01:21:23 -06003093void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3094 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3095 VkResult result) {
3096 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003097 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003098}
3099
Mike Schuchardt2df08912020-12-15 16:28:09 -08003100void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003101 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3102 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003103 if (VK_SUCCESS != result) return;
3104
Jeremy Gebben082a9832021-10-28 13:40:11 -06003105 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003106}
3107
Mike Schuchardt2df08912020-12-15 16:28:09 -08003108void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003109 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3110 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003111 if (VK_SUCCESS != result) return;
3112
Jeremy Gebben082a9832021-10-28 13:40:11 -06003113 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07003114}
3115
locke-lunargd556cc32019-09-17 01:21:23 -06003116void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3117 const VkRenderPassBeginInfo *pRenderPassBegin,
3118 VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003119 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003120 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003121}
3122
3123void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3124 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003125 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003126 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003127 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003128}
3129
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003130void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3131 uint32_t counterBufferCount,
3132 const VkBuffer *pCounterBuffers,
3133 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003134 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003135
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003136 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003137 cb_state->transform_feedback_active = true;
3138}
3139
3140void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3141 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3142 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003143 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003144
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003145 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003146 cb_state->transform_feedback_active = false;
3147}
3148
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003149void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3150 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003151 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003152
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003153 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003154 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003155 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3156 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003157}
3158
3159void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003160 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003161
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003162 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003163 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003164 cb_state->conditional_rendering_inside_render_pass = false;
3165 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003166}
3167
amhagana448ea52021-11-02 14:09:14 -04003168void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003169 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003170 cb_state->activeRenderPass = nullptr;
3171}
3172
3173void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
3174 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003175 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04003176 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
3177}
3178
Tony-LunarG40b33882021-12-02 12:40:11 -07003179void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
3180 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
3181 cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
3182}
3183
amhagana448ea52021-11-02 14:09:14 -04003184void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
3185 RecordCmdEndRenderingRenderPassState(commandBuffer);
3186}
3187
Tony-LunarG40b33882021-12-02 12:40:11 -07003188void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
3189 RecordCmdEndRenderingRenderPassState(commandBuffer);
3190}
3191
Tony-LunarG977448c2019-12-02 14:52:02 -07003192void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3193 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003194 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003195 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003196 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003197}
3198
locke-lunargd556cc32019-09-17 01:21:23 -06003199void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003200 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003201 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003202}
3203
3204void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003205 const VkSubpassBeginInfo *pSubpassBeginInfo,
3206 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003207 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003208 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003209}
3210
Tony-LunarG977448c2019-12-02 14:52:02 -07003211void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003212 const VkSubpassBeginInfo *pSubpassBeginInfo,
3213 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003214 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003215 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003216}
3217
3218void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003219 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003220 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003221}
3222
3223void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003224 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003225 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003226 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003227}
3228
Tony-LunarG977448c2019-12-02 14:52:02 -07003229void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003230 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003231 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003232 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003233}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003234
locke-lunargd556cc32019-09-17 01:21:23 -06003235void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3236 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003237 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003238
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003239 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003240}
3241
3242void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3243 VkFlags flags, void **ppData, VkResult result) {
3244 if (VK_SUCCESS != result) return;
3245 RecordMappedMemory(mem, offset, size, ppData);
3246}
3247
3248void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003249 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06003250 if (mem_info) {
3251 mem_info->mapped_range = MemRange();
3252 mem_info->p_driver_data = nullptr;
3253 }
3254}
3255
3256void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003257 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003258 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003259 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3260 // See: VUID-vkGetImageSubresourceLayout-image-01895
3261 image_state->fragment_encoder =
3262 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003263 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003264 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003265 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003266 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003267 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003268
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003269 if (!swapchain_image.fake_base_address) {
3270 auto size = image_state->fragment_encoder->TotalSize();
3271 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003272 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003273 // All images bound to this swapchain and index are aliases
3274 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003275 }
3276 } else {
3277 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06003278 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003279 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003280 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003281 }
locke-lunargd556cc32019-09-17 01:21:23 -06003282 }
locke-lunargd556cc32019-09-17 01:21:23 -06003283 }
3284}
3285
3286void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3287 VkDeviceSize memoryOffset, VkResult result) {
3288 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003289 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003290 bind_info.image = image;
3291 bind_info.memory = mem;
3292 bind_info.memoryOffset = memoryOffset;
3293 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003294}
3295
3296void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003297 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003298 if (VK_SUCCESS != result) return;
3299 for (uint32_t i = 0; i < bindInfoCount; i++) {
3300 UpdateBindImageMemoryState(pBindInfos[i]);
3301 }
3302}
3303
3304void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003305 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003306 if (VK_SUCCESS != result) return;
3307 for (uint32_t i = 0; i < bindInfoCount; i++) {
3308 UpdateBindImageMemoryState(pBindInfos[i]);
3309 }
3310}
3311
3312void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003313 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06003314 if (event_state) {
3315 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3316 }
locke-lunargd556cc32019-09-17 01:21:23 -06003317}
3318
3319void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3320 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3321 VkResult result) {
3322 if (VK_SUCCESS != result) return;
3323 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3324 pImportSemaphoreFdInfo->flags);
3325}
3326
3327void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003328 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003329 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003330 if (semaphore_state) {
3331 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003332 }
3333}
3334
3335#ifdef VK_USE_PLATFORM_WIN32_KHR
3336void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3337 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3338 if (VK_SUCCESS != result) return;
3339 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3340 pImportSemaphoreWin32HandleInfo->flags);
3341}
3342
3343void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3344 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3345 HANDLE *pHandle, VkResult result) {
3346 if (VK_SUCCESS != result) return;
3347 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3348}
3349
3350void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3351 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3352 if (VK_SUCCESS != result) return;
3353 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3354 pImportFenceWin32HandleInfo->flags);
3355}
3356
3357void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3358 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3359 HANDLE *pHandle, VkResult result) {
3360 if (VK_SUCCESS != result) return;
3361 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3362}
3363#endif
3364
3365void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3366 VkResult result) {
3367 if (VK_SUCCESS != result) return;
3368 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3369}
3370
Mike Schuchardt2df08912020-12-15 16:28:09 -08003371void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3372 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003373 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003374
3375 if (fence_node) {
3376 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06003377 }
3378}
3379
3380void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3381 VkResult result) {
3382 if (VK_SUCCESS != result) return;
3383 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3384}
3385
Mike Schuchardt2df08912020-12-15 16:28:09 -08003386void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003387 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003388 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003389 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003390 }
3391}
3392
3393void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3394 VkResult result) {
3395 if (VK_SUCCESS != result) return;
3396 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3397}
3398
3399void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3400 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3401 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003402 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003403}
3404
3405void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003406 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003407 SWAPCHAIN_NODE *old_swapchain_state) {
3408 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003409 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003410 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003411 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003412 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3413 surface_state->AddParent(swapchain.get());
3414 surface_state->swapchain = swapchain.get();
3415 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003416 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003417 } else {
3418 surface_state->swapchain = nullptr;
3419 }
3420 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003421 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003422 if (old_swapchain_state) {
3423 old_swapchain_state->retired = true;
3424 }
3425 return;
3426}
3427
3428void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3429 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3430 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003431 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003432 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003433 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003434}
3435
3436void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3437 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003438 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003439}
3440
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003441void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3442 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3443 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3444 VkResult result) {
3445 if (VK_SUCCESS != result) return;
3446 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003447 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003448}
3449
locke-lunargd556cc32019-09-17 01:21:23 -06003450void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003451 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003452 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003453 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
3454 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
3455 if (semaphore_state) {
3456 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003457 }
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003458 }
3459
3460 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
3461 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3462 // 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
3463 // confused itself just as much.
3464 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3465 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3466 // Mark the image as having been released to the WSI
3467 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
3468 if (swapchain_data) {
3469 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
3470 if (present_id_info) {
3471 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3472 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3473 }
ziga-lunarg2d289702022-03-21 18:45:51 +01003474 }
3475 }
locke-lunargd556cc32019-09-17 01:21:23 -06003476 }
locke-lunargd556cc32019-09-17 01:21:23 -06003477}
3478
3479void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3480 const VkSwapchainCreateInfoKHR *pCreateInfos,
3481 const VkAllocationCallbacks *pAllocator,
3482 VkSwapchainKHR *pSwapchains, VkResult result) {
3483 if (pCreateInfos) {
3484 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003485 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003486 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003487 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3488 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003489 }
3490 }
3491}
3492
3493void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3494 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003495 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003496 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003497 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3498 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003499 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003500 }
3501
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003502 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003503 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003504 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3505 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003506 semaphore_state->EnqueueAcquire();
ziga-lunarg69aa72f2022-03-29 15:24:35 +02003507 }
3508
3509 // Mark the image as acquired.
3510 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
3511 if (swapchain_data) {
3512 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003513 }
3514}
3515
3516void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3517 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3518 VkResult result) {
3519 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3520 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3521}
3522
3523void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3524 uint32_t *pImageIndex, VkResult result) {
3525 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3526 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3527 pAcquireInfo->fence, pImageIndex);
3528}
3529
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003530std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3531 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3532}
3533
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003534void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3535 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3536 VkResult result) {
3537 if (result != VK_SUCCESS) {
3538 return;
3539 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003540 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003541 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003542 // this can fail if the allocator fails
3543 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3544 if (result != VK_SUCCESS) {
3545 return;
3546 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003547 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003548 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3549 if (result != VK_SUCCESS) {
3550 return;
3551 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003552
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003553 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003554 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003555 }
3556}
3557
3558// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003559static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003560 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003561}
3562
3563void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3564 uint32_t *pQueueFamilyPropertyCount,
3565 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003566 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3567 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003568 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003569}
3570
3571void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003572 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003573 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3574 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003575 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003576}
3577
3578void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003579 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003580 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3581 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003582 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003583}
3584void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3585 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003586 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003587}
3588
Jeremy Gebben082a9832021-10-28 13:40:11 -06003589void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003590
3591void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3592 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3593 const VkAllocationCallbacks *pAllocator,
3594 VkSurfaceKHR *pSurface, VkResult result) {
3595 if (VK_SUCCESS != result) return;
3596 RecordVulkanSurface(pSurface);
3597}
3598
3599#ifdef VK_USE_PLATFORM_ANDROID_KHR
3600void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3601 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3602 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3603 VkResult result) {
3604 if (VK_SUCCESS != result) return;
3605 RecordVulkanSurface(pSurface);
3606}
3607#endif // VK_USE_PLATFORM_ANDROID_KHR
3608
3609#ifdef VK_USE_PLATFORM_IOS_MVK
3610void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3611 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3612 VkResult result) {
3613 if (VK_SUCCESS != result) return;
3614 RecordVulkanSurface(pSurface);
3615}
3616#endif // VK_USE_PLATFORM_IOS_MVK
3617
3618#ifdef VK_USE_PLATFORM_MACOS_MVK
3619void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3620 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3621 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3622 VkResult result) {
3623 if (VK_SUCCESS != result) return;
3624 RecordVulkanSurface(pSurface);
3625}
3626#endif // VK_USE_PLATFORM_MACOS_MVK
3627
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003628#ifdef VK_USE_PLATFORM_METAL_EXT
3629void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3630 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3631 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3632 VkResult result) {
3633 if (VK_SUCCESS != result) return;
3634 RecordVulkanSurface(pSurface);
3635}
3636#endif // VK_USE_PLATFORM_METAL_EXT
3637
locke-lunargd556cc32019-09-17 01:21:23 -06003638#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3639void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3640 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3641 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3642 VkResult result) {
3643 if (VK_SUCCESS != result) return;
3644 RecordVulkanSurface(pSurface);
3645}
3646#endif // VK_USE_PLATFORM_WAYLAND_KHR
3647
3648#ifdef VK_USE_PLATFORM_WIN32_KHR
3649void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3650 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3651 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3652 VkResult result) {
3653 if (VK_SUCCESS != result) return;
3654 RecordVulkanSurface(pSurface);
3655}
3656#endif // VK_USE_PLATFORM_WIN32_KHR
3657
3658#ifdef VK_USE_PLATFORM_XCB_KHR
3659void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3660 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3661 VkResult result) {
3662 if (VK_SUCCESS != result) return;
3663 RecordVulkanSurface(pSurface);
3664}
3665#endif // VK_USE_PLATFORM_XCB_KHR
3666
3667#ifdef VK_USE_PLATFORM_XLIB_KHR
3668void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3669 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3670 VkResult result) {
3671 if (VK_SUCCESS != result) return;
3672 RecordVulkanSurface(pSurface);
3673}
3674#endif // VK_USE_PLATFORM_XLIB_KHR
3675
Niklas Haas8b84af12020-04-19 22:20:11 +02003676void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3677 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3678 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3679 VkResult result) {
3680 if (VK_SUCCESS != result) return;
3681 RecordVulkanSurface(pSurface);
3682}
3683
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003684void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3685 VkSurfaceKHR surface,
3686 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3687 VkResult result) {
3688 if (VK_SUCCESS != result) return;
3689 auto surface_state = Get<SURFACE_STATE>(surface);
3690 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3691}
3692
3693void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3694 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3695 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3696 if (VK_SUCCESS != result) return;
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003697
3698 if (pSurfaceInfo->surface) {
3699 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3700 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3701 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
3702 lvl_find_in_chain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
3703 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3704 assert(pd_state);
3705 pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
3706 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003707}
3708
3709void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3710 VkSurfaceKHR surface,
3711 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3712 VkResult result) {
3713 auto surface_state = Get<SURFACE_STATE>(surface);
3714 VkSurfaceCapabilitiesKHR caps{
3715 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3716 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3717 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3718 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3719 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3720 };
3721 surface_state->SetCapabilities(physicalDevice, caps);
3722}
3723
locke-lunargd556cc32019-09-17 01:21:23 -06003724void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3725 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3726 VkBool32 *pSupported, VkResult result) {
3727 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003728 auto surface_state = Get<SURFACE_STATE>(surface);
3729 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3730}
3731
3732void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3733 VkSurfaceKHR surface,
3734 uint32_t *pPresentModeCount,
3735 VkPresentModeKHR *pPresentModes,
3736 VkResult result) {
3737 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3738
3739 if (pPresentModes) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003740 if (surface) {
3741 auto surface_state = Get<SURFACE_STATE>(surface);
3742 surface_state->SetPresentModes(physicalDevice,
3743 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3744 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3745 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3746 assert(pd_state);
3747 pd_state->surfaceless_query_state.present_modes =
3748 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
3749 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003750 }
3751}
3752
3753void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3754 uint32_t *pSurfaceFormatCount,
3755 VkSurfaceFormatKHR *pSurfaceFormats,
3756 VkResult result) {
3757 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3758
3759 if (pSurfaceFormats) {
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003760 if (surface) {
3761 auto surface_state = Get<SURFACE_STATE>(surface);
3762 surface_state->SetFormats(physicalDevice,
3763 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3764 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3765 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3766 assert(pd_state);
3767 pd_state->surfaceless_query_state.formats =
3768 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
3769 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003770 }
3771}
3772
3773void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3774 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3775 uint32_t *pSurfaceFormatCount,
3776 VkSurfaceFormat2KHR *pSurfaceFormats,
3777 VkResult result) {
3778 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3779
3780 if (pSurfaceFormats) {
3781 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003782 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3783 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3784 }
Mark Lobodzinski4ed67b12022-03-30 17:00:10 -06003785 if (pSurfaceInfo->surface) {
3786 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3787 surface_state->SetFormats(physicalDevice, std::move(fmts));
3788 } else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
3789 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3790 assert(pd_state);
3791 pd_state->surfaceless_query_state.formats = std::move(fmts);
3792 }
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003793 }
locke-lunargd556cc32019-09-17 01:21:23 -06003794}
3795
locke-lunargd556cc32019-09-17 01:21:23 -06003796void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3797 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003798 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003799 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003800 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3801}
3802
3803void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003804 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003805 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003806 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3807}
3808
3809void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3810 const VkDebugUtilsLabelEXT *pLabelInfo) {
3811 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3812
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003813 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003814 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3815 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003816 cb_state->debug_label = LoggingLabel(pLabelInfo);
3817}
3818
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003819void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3820 uint32_t queueFamilyIndex,
3821 uint32_t *pCounterCount,
3822 VkPerformanceCounterKHR *pCounters) {
3823 if (NULL == pCounters) return;
3824
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003825 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3826 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003827
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003828 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3829 queue_family_counters->counters.resize(*pCounterCount);
3830 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003831
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003832 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003833}
3834
3835void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3836 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3837 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3838 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3839 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3840}
3841
3842void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3843 VkResult result) {
3844 if (result == VK_SUCCESS) performance_lock_acquired = true;
3845}
3846
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003847void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3848 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003849 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003850 cmd_buffer.second->performance_lock_released = true;
3851 }
3852}
3853
locke-lunargd556cc32019-09-17 01:21:23 -06003854void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003855 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003856 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003857 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003858}
3859
3860void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003861 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003862 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003863 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003864}
3865
Mike Schuchardt2df08912020-12-15 16:28:09 -08003866void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3867 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003868 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003869}
3870
Mike Schuchardt2df08912020-12-15 16:28:09 -08003871void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3872 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3873 const VkAllocationCallbacks *pAllocator,
3874 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3875 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003876 if (VK_SUCCESS != result) return;
3877 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3878}
3879
3880void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003881 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3882 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003883 if (VK_SUCCESS != result) return;
3884 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3885}
3886
3887void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003888 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003889 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003890 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3891 assert(template_state);
3892 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003893 // TODO: Record template push descriptor updates
3894 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003895 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003896 }
3897 }
3898}
3899
3900void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3901 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3902 const void *pData) {
3903 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3904}
3905
3906void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003907 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003908 const void *pData) {
3909 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3910}
3911
Mike Schuchardt2df08912020-12-15 16:28:09 -08003912void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3913 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3914 VkPipelineLayout layout, uint32_t set,
3915 const void *pData) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003916 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003917
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003918 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenf4449392022-01-28 10:09:10 -07003919 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003920 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003921 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003922 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003923 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003924 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003925 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003926 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003927 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003928 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3929 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003930 }
3931}
3932
3933void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3934 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003935 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003936 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003937 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003938 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003939 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003940 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003941 }
3942}
3943
3944void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3945 uint32_t *pPropertyCount,
3946 VkDisplayPlanePropertiesKHR *pProperties,
3947 VkResult result) {
3948 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3949 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3950}
3951
3952void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3953 uint32_t *pPropertyCount,
3954 VkDisplayPlaneProperties2KHR *pProperties,
3955 VkResult result) {
3956 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3957 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3958}
3959
3960void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3961 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3962 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003963 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003964 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003965 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003966}
3967
3968void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3969 uint32_t query, uint32_t index) {
3970 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07003971 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003972 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003973 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003974}
3975
3976void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3977 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003978 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003979
3980 if (create_info->format != VK_FORMAT_UNDEFINED) {
3981 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003982 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003983 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3984 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003985 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003986
Jeremy Gebben082a9832021-10-28 13:40:11 -06003987 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003988}
3989
3990void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3991 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3992 const VkAllocationCallbacks *pAllocator,
3993 VkSamplerYcbcrConversion *pYcbcrConversion,
3994 VkResult result) {
3995 if (VK_SUCCESS != result) return;
3996 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3997}
3998
3999void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4000 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4001 const VkAllocationCallbacks *pAllocator,
4002 VkSamplerYcbcrConversion *pYcbcrConversion,
4003 VkResult result) {
4004 if (VK_SUCCESS != result) return;
4005 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4006}
4007
4008void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4009 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004010 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004011}
4012
4013void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4014 VkSamplerYcbcrConversion ycbcrConversion,
4015 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06004016 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004017}
4018
Tony-LunarG977448c2019-12-02 14:52:02 -07004019void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4020 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004021 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004022 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004023
4024 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004025 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06004026 if (!query_pool_state) return;
4027
4028 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06004029 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4030 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004031 auto query_index = firstQuery + i;
4032 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004033 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004034 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07004035 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004036 }
4037 }
locke-lunargd556cc32019-09-17 01:21:23 -06004038 }
4039}
4040
Tony-LunarG977448c2019-12-02 14:52:02 -07004041void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4042 uint32_t queryCount) {
4043 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4044}
4045
4046void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4047 uint32_t queryCount) {
4048 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4049}
4050
locke-lunargd556cc32019-09-17 01:21:23 -06004051void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06004052 const UPDATE_TEMPLATE_STATE *template_state,
4053 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06004054 // Translate the templated update into a normal update for validation...
4055 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4056 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4057 decoded_update.desc_writes.data(), 0, NULL);
4058}
4059
4060// Update the common AllocateDescriptorSetsData
4061void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004062 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004063 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004064 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004065 if (layout) {
4066 ds_data->layout_nodes[i] = layout;
4067 // Count total descriptors required per type
4068 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4069 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004070 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4071 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004072 }
4073 }
4074 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4075 }
4076}
4077
locke-lunargd556cc32019-09-17 01:21:23 -06004078void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4079 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004080 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004081 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004082}
4083
Tony-LunarG745150c2021-07-02 15:07:31 -06004084void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4085 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4086 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004087 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004088 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004089}
4090
locke-lunargd556cc32019-09-17 01:21:23 -06004091void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4092 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4093 uint32_t firstInstance) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004094 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004095 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004096}
4097
Tony-LunarG745150c2021-07-02 15:07:31 -06004098void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4099 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4100 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4101 const int32_t *pVertexOffset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004102 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004103 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004104}
4105
locke-lunargd556cc32019-09-17 01:21:23 -06004106void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4107 uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004108 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004109 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004110 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004111 if (!disabled[command_buffer_state]) {
4112 cb_state->AddChild(buffer_state);
4113 }
locke-lunargd556cc32019-09-17 01:21:23 -06004114}
4115
4116void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4117 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004118 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004119 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004120 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004121 if (!disabled[command_buffer_state]) {
4122 cb_state->AddChild(buffer_state);
4123 }
locke-lunargd556cc32019-09-17 01:21:23 -06004124}
4125
4126void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004127 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004128 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004129}
4130
4131void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4132 VkDeviceSize offset) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004133 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004134 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004135 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004136 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004137 cb_state->AddChild(buffer_state);
4138 }
locke-lunargd556cc32019-09-17 01:21:23 -06004139}
4140
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004141void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4142 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004143 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004144 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4145}
4146
4147void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
4148 uint32_t, uint32_t) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004149 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06004150 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
4151}
4152
Tony-LunarG977448c2019-12-02 14:52:02 -07004153void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4154 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004155 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004156 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004157 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004158 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004159 auto buffer_state = Get<BUFFER_STATE>(buffer);
4160 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004161 cb_state->AddChild(buffer_state);
4162 cb_state->AddChild(count_buffer_state);
4163 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004164}
4165
locke-lunargd556cc32019-09-17 01:21:23 -06004166void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4167 VkDeviceSize offset, VkBuffer countBuffer,
4168 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4169 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004170 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004171 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004172}
4173
4174void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4175 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4176 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004177 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004178 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004179}
4180
4181void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4182 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004183 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004184 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004185 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004186 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004187 auto buffer_state = Get<BUFFER_STATE>(buffer);
4188 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004189 cb_state->AddChild(buffer_state);
4190 cb_state->AddChild(count_buffer_state);
4191 }
locke-lunargd556cc32019-09-17 01:21:23 -06004192}
4193
4194void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4195 VkDeviceSize offset, VkBuffer countBuffer,
4196 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4197 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004198 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004199 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004200}
4201
4202void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4203 VkDeviceSize offset, VkBuffer countBuffer,
4204 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4205 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004206 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004207 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004208}
4209
4210void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4211 uint32_t firstTask) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004212 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004213 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004214}
4215
4216void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4217 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004218 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004219 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004220 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004221 if (!disabled[command_buffer_state] && buffer_state) {
4222 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004223 }
4224}
4225
4226void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4227 VkDeviceSize offset, VkBuffer countBuffer,
4228 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4229 uint32_t stride) {
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->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004232 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004233 auto buffer_state = Get<BUFFER_STATE>(buffer);
4234 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004235 if (buffer_state) {
4236 cb_state->AddChild(buffer_state);
4237 }
4238 if (count_buffer_state) {
4239 cb_state->AddChild(count_buffer_state);
4240 }
locke-lunargd556cc32019-09-17 01:21:23 -06004241 }
4242}
4243
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004244void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4245 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4246 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4247 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4248 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4249 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4250 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004251 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004252 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004253 cb_state->hasTraceRaysCmd = true;
4254}
4255
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004256void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4257 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4258 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4259 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4260 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4261 uint32_t height, uint32_t depth) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004262 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004263 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004264 cb_state->hasTraceRaysCmd = true;
4265}
4266
4267void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4268 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4269 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4270 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4271 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4272 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004273 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004274 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004275 cb_state->hasTraceRaysCmd = true;
4276}
4277
locke-lunargd556cc32019-09-17 01:21:23 -06004278void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4279 const VkAllocationCallbacks *pAllocator,
4280 VkShaderModule *pShaderModule, VkResult result,
4281 void *csm_state_data) {
4282 if (VK_SUCCESS != result) return;
4283 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4284
sfricke-samsung45996a42021-09-16 13:45:27 -07004285 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004286 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004287 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4288 csm_state->unique_shader_id)
4289 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004290 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06004291}
4292
John Zulauf22b0fbe2019-10-15 06:26:16 -06004293void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4294 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4295 VkResult result) {
4296 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06004297 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004298
4299 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4300
4301 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004302 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004303 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004304 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004305
Lionel Landwerlin15ed1f62022-01-12 16:54:05 +02004306 auto format_features = GetImageFormatFeatures(
4307 physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
4308 pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004309
Jeremy Gebben20da7a12022-02-25 14:07:46 -07004310 auto image_state =
4311 CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004312 if (!swapchain_image.fake_base_address) {
4313 auto size = image_state->fragment_encoder->TotalSize();
4314 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004315 }
4316
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004317 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004318 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06004319 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06004320 }
4321 }
4322
4323 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004324 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4325 }
4326}
sourav parmar35e7a002020-06-09 17:58:44 -07004327
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004328void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
4329 const VkCopyAccelerationStructureInfoKHR *pInfo,
4330 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004331 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4332 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02004333 if (dst_as_state != nullptr && src_as_state != nullptr) {
4334 dst_as_state->built = true;
4335 dst_as_state->build_info_khr = src_as_state->build_info_khr;
4336 }
4337}
4338
sourav parmar35e7a002020-06-09 17:58:44 -07004339void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4340 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004341 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004342 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004343 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004344 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4345 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004346 if (dst_as_state != nullptr && src_as_state != nullptr) {
4347 dst_as_state->built = true;
4348 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004349 if (!disabled[command_buffer_state]) {
4350 cb_state->AddChild(dst_as_state);
4351 cb_state->AddChild(src_as_state);
4352 }
sourav parmar35e7a002020-06-09 17:58:44 -07004353 }
4354 }
4355}
Piers Daniell39842ee2020-07-10 16:42:33 -06004356
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004357void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
4358 VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
4359 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4360 if (cb_state) {
4361 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
4362 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
4363 if (!disabled[command_buffer_state]) {
4364 cb_state->AddChild(src_as_state);
4365 }
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004366 auto dst_buffer = GetBufferByAddress(pInfo->dst.deviceAddress);
4367 if (dst_buffer) {
4368 cb_state->AddChild(dst_buffer);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004369 }
4370 }
4371}
4372
4373void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
4374 VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
4375 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4376 if (cb_state) {
4377 cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
4378 if (!disabled[command_buffer_state]) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004379 auto buffer_state = GetBufferByAddress(pInfo->src.deviceAddress);
4380 if (buffer_state) {
4381 cb_state->AddChild(buffer_state);
Jeremy Gebbenf57d8442022-02-22 10:55:48 -07004382 }
4383 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
4384 cb_state->AddChild(dst_as_state);
4385 }
4386 }
4387}
4388
Piers Daniell39842ee2020-07-10 16:42:33 -06004389void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004390 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004391 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004392}
4393
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004394void ValidationStateTracker::PreCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
4395 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4396 cb_state->RecordStateCmd(CMD_SETCULLMODE, CBSTATUS_CULL_MODE_SET);
4397}
4398
Piers Daniell39842ee2020-07-10 16:42:33 -06004399void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004400 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004401 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004402}
4403
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004404void ValidationStateTracker::PreCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
4405 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4406 cb_state->RecordStateCmd(CMD_SETFRONTFACE, CBSTATUS_FRONT_FACE_SET);
4407}
4408
Piers Daniell39842ee2020-07-10 16:42:33 -06004409void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4410 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004411 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004412 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004413 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004414}
4415
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004416void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
4417 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004418 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004419 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGY, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
4420 cb_state->primitiveTopology = primitiveTopology;
4421}
4422
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004423void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4424 const VkViewport *pViewports, CMD_TYPE cmdType) {
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004425 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4426 cb_state->RecordStateCmd(cmdType, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004427 uint32_t bits = (1u << viewportCount) - 1u;
4428 cb_state->viewportWithCountMask |= bits;
4429 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004430 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004431 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004432
4433 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4434 for (size_t i = 0; i < viewportCount; ++i) {
4435 cb_state->dynamicViewports[i] = pViewports[i];
4436 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004437}
4438
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004439void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4440 const VkViewport *pViewports) {
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004441 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004442}
4443
4444void ValidationStateTracker::PreCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
Tony-LunarG8d71c4f2022-01-27 15:25:53 -07004445 const VkViewport *pViewports) {
4446 RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004447}
4448
4449void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4450 const VkRect2D *pScissors, CMD_TYPE cmdType) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004451 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004452 cb_state->RecordStateCmd(cmdType, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004453 uint32_t bits = (1u << scissorCount) - 1u;
4454 cb_state->scissorWithCountMask |= bits;
4455 cb_state->trashedScissorMask &= ~bits;
4456 cb_state->scissorWithCountCount = scissorCount;
4457 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004458}
4459
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004460void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4461 const VkRect2D *pScissors) {
4462 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
4463}
4464
4465void ValidationStateTracker::PreCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4466 const VkRect2D *pScissors) {
4467 RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
4468}
4469
4470void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4471 uint32_t bindingCount, const VkBuffer *pBuffers,
4472 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4473 const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004474 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004475 cb_state->RecordStateCmd(cmd_type, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004476
4477 uint32_t end = firstBinding + bindingCount;
4478 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4479 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4480 }
4481
4482 for (uint32_t i = 0; i < bindingCount; ++i) {
4483 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004484 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004485 vertex_buffer_binding.offset = pOffsets[i];
4486 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4487 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4488 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004489 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004490 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004491 }
4492 }
4493}
4494
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004495void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4496 uint32_t bindingCount, const VkBuffer *pBuffers,
4497 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4498 const VkDeviceSize *pStrides) {
4499 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4500 CMD_BINDVERTEXBUFFERS2EXT);
4501}
4502
4503void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4504 uint32_t bindingCount, const VkBuffer *pBuffers,
4505 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4506 const VkDeviceSize *pStrides) {
4507 RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
4508 CMD_BINDVERTEXBUFFERS2);
4509}
4510
Piers Daniell39842ee2020-07-10 16:42:33 -06004511void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004512 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004513 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004514}
4515
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004516void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
4517 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4518 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLE, CBSTATUS_DEPTH_TEST_ENABLE_SET);
4519}
4520
Piers Daniell39842ee2020-07-10 16:42:33 -06004521void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
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_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004524}
4525
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004526void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
4527 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4528 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLE, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
4529}
4530
Piers Daniell39842ee2020-07-10 16:42:33 -06004531void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004532 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004533 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004534}
4535
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004536void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
4537 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4538 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CBSTATUS_DEPTH_COMPARE_OP_SET);
4539}
4540
Piers Daniell39842ee2020-07-10 16:42:33 -06004541void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4542 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004543 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004544 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004545}
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004546
4547void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
4548 VkBool32 depthBoundsTestEnable) {
4549 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4550 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLE, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
4551}
4552
Piers Daniell39842ee2020-07-10 16:42:33 -06004553void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
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_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004556}
4557
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004558void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
4559 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4560 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLE, CBSTATUS_STENCIL_TEST_ENABLE_SET);
4561}
4562
Piers Daniell39842ee2020-07-10 16:42:33 -06004563void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4564 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4565 VkCompareOp compareOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004566 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004567 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004568}
locke-lunarg4189aa22020-10-21 00:23:48 -06004569
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004570void ValidationStateTracker::PreCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4571 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4572 VkCompareOp compareOp) {
4573 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4574 cb_state->RecordStateCmd(CMD_SETSTENCILOP, CBSTATUS_STENCIL_OP_SET);
4575}
4576
locke-lunarg4189aa22020-10-21 00:23:48 -06004577void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4578 uint32_t discardRectangleCount,
4579 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004580 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004581 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004582}
4583
4584void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4585 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004586 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004587 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004588}
4589
4590void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4591 VkCoarseSampleOrderTypeNV sampleOrderType,
4592 uint32_t customSampleOrderCount,
4593 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004594 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004595 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004596}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004597
4598void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004599 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004600 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004601}
4602
4603void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004604 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004605 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004606}
4607
4608void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4609 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004610 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004611 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004612}
4613
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004614void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
4615 VkBool32 rasterizerDiscardEnable) {
4616 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4617 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLE, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
4618}
4619
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004620void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004621 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004622 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004623}
4624
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004625void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
4626 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4627 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLE, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
4628}
4629
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004630void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4631 VkBool32 primitiveRestartEnable) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004632 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004633 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004634}
Piers Daniell924cd832021-05-18 13:48:47 -06004635
Tony-LunarG3f953ba2021-10-15 15:35:39 -06004636void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
4637 VkBool32 primitiveRestartEnable) {
4638 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4639 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLE, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
4640}
4641
Piers Daniell924cd832021-05-18 13:48:47 -06004642void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4643 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4644 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4645 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07004646 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004647 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4648
4649 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4650 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4651 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004652 if (pipeline_state->create_info.graphics.pDynamicState) {
4653 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4654 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004655 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4656 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4657 break;
4658 }
4659 }
4660 }
4661 }
4662 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004663}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004664
ziga-lunarg67b7c392022-03-26 01:45:34 +01004665void ValidationStateTracker::PreCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
4666 const VkBool32 *pColorWriteEnables) {
4667 auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
4668 const CBStatusFlags status_flags = CBSTATUS_COLOR_WRITE_ENABLE_SET;
4669 cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, status_flags, attachmentCount);
4670}
4671
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004672void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004673 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Jeremy Gebben8c3b41e2022-02-16 15:15:47 -07004674 if (buffer_state && address != 0) {
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004675 WriteLockGuard guard(buffer_address_lock_);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004676 // address is used for GPU-AV and ray tracing buffer validation
4677 buffer_state->deviceAddress = address;
Jeremy Gebbenc1063462022-02-11 09:31:18 -07004678 buffer_address_map_.insert({buffer_state->DeviceAddressRange(), buffer_state});
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004679 }
4680}
4681
4682void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4683 VkDeviceAddress address) {
4684 RecordGetBufferDeviceAddress(pInfo, address);
4685}
4686
4687void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4688 VkDeviceAddress address) {
4689 RecordGetBufferDeviceAddress(pInfo, address);
4690}
4691
4692void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4693 VkDeviceAddress address) {
4694 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004695}
4696
4697std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4698 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004699 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004700}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004701
4702std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4703 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004704 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004705 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4706}