blob: 3ebd4f70c811e563b23c491c4e3db8942072a164 [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
Jeremy Gebben11af9792021-08-20 10:20:09 -060042extern template PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *, const VkRayTracingPipelineCreateInfoKHR *,
43 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&);
44extern template PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *, const VkRayTracingPipelineCreateInfoNV *,
45 std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&);
46
Mark Lobodzinskib4ab6ac2020-04-02 13:12:06 -060047void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) {
48 if (add_obj) {
49 instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type));
50 // Call base class
51 ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj);
52 }
53}
54
John Zulauf2bc1fde2020-04-24 15:09:51 -060055// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
56// attachments won't persist past the API entry point exit.
Jeremy Gebben88f58142021-06-01 10:07:52 -060057static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
58 const FRAMEBUFFER_STATE &fb_state) {
John Zulauf2bc1fde2020-04-24 15:09:51 -060059 const VkImageView *attachments = fb_state.createInfo.pAttachments;
60 uint32_t count = fb_state.createInfo.attachmentCount;
61 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -070062 const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
John Zulauf2bc1fde2020-04-24 15:09:51 -060063 if (framebuffer_attachments) {
64 attachments = framebuffer_attachments->pAttachments;
65 count = framebuffer_attachments->attachmentCount;
66 }
67 }
68 return std::make_pair(count, attachments);
69}
70
John Zulauf64ffe552021-02-06 10:25:07 -070071template <typename ImageViewPointer, typename Get>
72std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
73 const Get &get_fn) {
74 std::vector<ImageViewPointer> views;
John Zulauf2bc1fde2020-04-24 15:09:51 -060075
76 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
77 const auto attachment_count = count_attachment.first;
78 const auto *attachments = count_attachment.second;
79 views.resize(attachment_count, nullptr);
80 for (uint32_t i = 0; i < attachment_count; i++) {
81 if (attachments[i] != VK_NULL_HANDLE) {
John Zulauf64ffe552021-02-06 10:25:07 -070082 views[i] = get_fn(attachments[i]);
John Zulauf2bc1fde2020-04-24 15:09:51 -060083 }
84 }
85 return views;
86}
87
Jeremy Gebben9f537102021-10-05 16:37:12 -060088std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
John Zulauf64ffe552021-02-06 10:25:07 -070089 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
Jeremy Gebben9f537102021-10-05 16:37:12 -060090 auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
John Zulauf64ffe552021-02-06 10:25:07 -070091 return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
92}
93
locke-lunargd556cc32019-09-17 01:21:23 -060094#ifdef VK_USE_PLATFORM_ANDROID_KHR
95// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
96// This could also move into a seperate core_validation_android.cpp file... ?
97
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -060098template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +020099VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600100 VkFormatFeatureFlags format_features = 0;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700101 const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600102 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700103 // VUID 01894 will catch if not found in map
104 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
105 if (it != ahb_ext_formats_map.end()) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600106 format_features = it->second;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700107 }
locke-lunargd556cc32019-09-17 01:21:23 -0600108 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600109 return format_features;
locke-lunargd556cc32019-09-17 01:21:23 -0600110}
111
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700112void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
113 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
114 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200115 auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
116 if (ahb_format_props2) {
117 ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
118 } else {
119 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
120 if (ahb_format_props) {
121 ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
122 static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
123 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700124 }
125}
126
locke-lunargd556cc32019-09-17 01:21:23 -0600127#else
128
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600129template <typename CreateInfo>
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200130VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600131 return 0;
132}
locke-lunargd556cc32019-09-17 01:21:23 -0600133
134#endif // VK_USE_PLATFORM_ANDROID_KHR
135
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600136VkFormatFeatureFlags GetImageFormatFeatures(VkPhysicalDevice physical_device, VkDevice device, VkImage image, VkFormat format,
137 VkImageTiling tiling) {
138 VkFormatFeatureFlags format_features = 0;
Petr Kraus44f1c482020-04-25 20:09:25 +0200139 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
140 // if format is AHB external format then the features are already set
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600141 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
142 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
143 nullptr};
144 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200145
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600146 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
147 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
148 nullptr};
149 format_properties_2.pNext = (void *)&drm_properties_list;
150 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
151 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
152 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
153 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
154 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200155
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600156 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
157 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
158 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
159 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200160 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200161 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600162 } else {
163 VkFormatProperties format_properties;
164 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
165 format_features =
166 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200167 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200169}
170
locke-lunargd556cc32019-09-17 01:21:23 -0600171void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
172 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
173 if (VK_SUCCESS != result) return;
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200174 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700175 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600176 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600177 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600178 if (format_features == 0) {
179 format_features = GetImageFormatFeatures(physical_device, device, *pImage, pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600180 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600181 Add(std::make_shared<IMAGE_STATE>(this, *pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600182}
183
184void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600185 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600186}
187
188void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
189 VkImageLayout imageLayout, const VkClearColorValue *pColor,
190 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600191 if (disabled[command_buffer_state]) return;
192
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600193 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600194 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600195 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600196 }
197}
198
199void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
200 VkImageLayout imageLayout,
201 const VkClearDepthStencilValue *pDepthStencil,
202 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600203 if (disabled[command_buffer_state]) return;
204
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600205 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600206 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600207 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600208 }
209}
210
211void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
212 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
213 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600214 if (disabled[command_buffer_state]) return;
215
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600216 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600217 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600218}
219
Jeff Leger178b1e52020-10-05 12:22:23 -0400220void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
221 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600222 if (disabled[command_buffer_state]) return;
223
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600224 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600225 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
226 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400227}
228
locke-lunargd556cc32019-09-17 01:21:23 -0600229void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
230 VkImageLayout srcImageLayout, VkImage dstImage,
231 VkImageLayout dstImageLayout, uint32_t regionCount,
232 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600233 if (disabled[command_buffer_state]) return;
234
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600235 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600236 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600237}
238
Jeff Leger178b1e52020-10-05 12:22:23 -0400239void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
240 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600241 if (disabled[command_buffer_state]) return;
242
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600243 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600244 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
245 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400246}
247
locke-lunargd556cc32019-09-17 01:21:23 -0600248void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
249 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
250 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600251 if (disabled[command_buffer_state]) return;
252
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600253 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600254 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600255}
256
Jeff Leger178b1e52020-10-05 12:22:23 -0400257void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
258 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600259 if (disabled[command_buffer_state]) return;
260
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600261 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600262 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
263 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400264}
265
locke-lunargd556cc32019-09-17 01:21:23 -0600266void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
267 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
268 VkResult result) {
269 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600270
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600271 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600272
James Rumble2f6e7bb2021-07-13 15:21:20 +0100273 if (pCreateInfo) {
274 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
275 if (opaque_capture_address) {
276 // address is used for GPU-AV and ray tracing buffer validation
277 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebben65975ed2021-10-29 11:16:10 -0600278 buffer_address_map_.insert(opaque_capture_address->opaqueCaptureAddress, buffer_state.get());
James Rumble2f6e7bb2021-07-13 15:21:20 +0100279 }
280 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600281 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600282}
283
284void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
285 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
286 VkResult result) {
287 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600288
Jeremy Gebben9f537102021-10-05 16:37:12 -0600289 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600290
291 VkFormatProperties format_properties;
292 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
locke-lunarg25b6c352020-08-06 17:44:18 -0600293
Jeremy Gebben082a9832021-10-28 13:40:11 -0600294 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, format_properties.bufferFeatures));
locke-lunargd556cc32019-09-17 01:21:23 -0600295}
296
297void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
298 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
299 VkResult result) {
300 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600301 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700302
Lionel Landwerlin21719f62021-12-09 11:40:09 +0200303 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600304 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700305 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600306 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700307 } else {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600308 format_features = GetImageFormatFeatures(physical_device, device, image_state->image(), pCreateInfo->format,
309 image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700310 }
311
locke-lunarg9939d4b2020-10-26 20:11:08 -0600312 // 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 -0600313 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600314 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700315 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600316 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700317 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600318 image_format_info.type = image_state->createInfo.imageType;
319 image_format_info.format = image_state->createInfo.format;
320 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600321 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
322 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600323 image_format_info.flags = image_state->createInfo.flags;
324
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600325 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600326
327 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
328 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600329
Jeremy Gebben082a9832021-10-28 13:40:11 -0600330 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600331}
332
333void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
334 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600335 if (disabled[command_buffer_state]) return;
336
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600337 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600338 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600339}
340
Jeff Leger178b1e52020-10-05 12:22:23 -0400341void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600342 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600343 if (disabled[command_buffer_state]) return;
344
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600345 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600346 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
347 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400348}
349
locke-lunargd556cc32019-09-17 01:21:23 -0600350void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
351 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600352 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600353}
354
355void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600356 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600357}
358
359void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
360 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600361 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600362}
363
364void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
365 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600366 if (disabled[command_buffer_state]) return;
367
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600368 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600369 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600370}
371
372void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
373 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
374 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600375 if (disabled[command_buffer_state]) return;
376
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600377 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600378
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600379 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600380}
381
Jeff Leger178b1e52020-10-05 12:22:23 -0400382void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
383 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600384 if (disabled[command_buffer_state]) return;
385
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600386 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600387 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
388 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400389}
390
locke-lunargd556cc32019-09-17 01:21:23 -0600391void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
392 VkImageLayout dstImageLayout, uint32_t regionCount,
393 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600394 if (disabled[command_buffer_state]) return;
395
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600396 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600397 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600398}
399
Jeff Leger178b1e52020-10-05 12:22:23 -0400400void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
401 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600402 if (disabled[command_buffer_state]) return;
403
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600404 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600405 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
406 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400407}
408
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700409// Gets union of all features defined by Potential Format Features
410// 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 +0200411VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
412 VkFormatFeatureFlags2KHR format_features = 0;
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700413
414 if (format != VK_FORMAT_UNDEFINED) {
415 VkFormatProperties format_properties;
416 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
417 format_features |= format_properties.linearTilingFeatures;
418 format_features |= format_properties.optimalTilingFeatures;
sfricke-samsung45996a42021-09-16 13:45:27 -0700419 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700420 // VK_KHR_get_physical_device_properties2 is required in this case
421 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
422 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
423 nullptr};
424 format_properties_2.pNext = (void *)&drm_properties_list;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100425
426 // First call is to get the number of modifiers compatible with the queried format
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700427 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100428
429 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
430 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
431 drm_properties_list.pDrmFormatModifierProperties = drm_properties.data();
432
433 // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers
434 // compatible with the queried format
435 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
436
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700437 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
438 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
439 }
440 }
441 }
442
443 return format_features;
444}
445
locke-lunargd556cc32019-09-17 01:21:23 -0600446void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
447 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
448 VkResult result) {
449 if (VK_SUCCESS != result) return;
450
Locke Linf3873542021-04-26 11:25:10 -0600451 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
452 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
453 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
454
locke-lunargd556cc32019-09-17 01:21:23 -0600455 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
456 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700457 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600458 if (features2) {
459 enabled_features_found = &(features2->features);
460 }
461 }
462
locke-lunargd556cc32019-09-17 01:21:23 -0600463 if (nullptr == enabled_features_found) {
464 state_tracker->enabled_features.core = {};
465 } else {
466 state_tracker->enabled_features.core = *enabled_features_found;
467 }
468
locke-lunargd556cc32019-09-17 01:21:23 -0600469 // Save local link to this device's physical device state
Jeremy Gebben9f537102021-10-05 16:37:12 -0600470 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
locke-lunargd556cc32019-09-17 01:21:23 -0600471
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700472 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700473 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700474 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700475 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700476 // Set Extension Feature Aliases to false as there is no struct to check
477 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
478 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
479 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
480 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
481 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
482 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800483 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700484
485 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700486
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700487 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700488 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700489 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
490 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
491 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
492 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700493 }
494
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700495 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700496 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700497 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
498 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700499 }
500
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700501 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700502 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700503 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
504 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
505 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
506 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
507 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
508 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
509 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
510 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
511 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
512 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
513 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
514 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
515 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
516 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
517 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
518 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
519 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
520 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
521 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
522 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
523 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
524 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
525 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
526 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
527 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
528 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
529 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
530 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
531 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
532 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
533 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
534 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
535 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
536 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
537 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
538 descriptor_indexing_features->descriptorBindingPartiallyBound;
539 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
540 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
541 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700542 }
543
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700544 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700545 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700546 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700547 }
548
549 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700550 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700551 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700552 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700553 }
554
555 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700556 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700557 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700558 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
559 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700560 }
561
562 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700563 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700564 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700565 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
566 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700567 }
568
569 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700570 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700571 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700572 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
573 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700574 }
575
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700576 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700577 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700578 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700579 }
580
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700581 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700582 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700583 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700584 }
585
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700586 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700587 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700588 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
589 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
590 buffer_device_address->bufferDeviceAddressCaptureReplay;
591 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
592 buffer_device_address->bufferDeviceAddressMultiDevice;
593 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800594
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700595 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800596 if (atomic_int64_features) {
597 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
598 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
599 }
600
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700601 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800602 if (memory_model_features) {
603 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
604 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
605 memory_model_features->vulkanMemoryModelDeviceScope;
606 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
607 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
608 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700609 }
610
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700611 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700612 if (vulkan_11_features) {
613 state_tracker->enabled_features.core11 = *vulkan_11_features;
614 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700615 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700616
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700617 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700618 if (sixteen_bit_storage_features) {
619 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
620 sixteen_bit_storage_features->storageBuffer16BitAccess;
621 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
622 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
623 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
624 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
625 }
626
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700627 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700628 if (multiview_features) {
629 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
630 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
631 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
632 }
633
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700634 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700635 if (variable_pointers_features) {
636 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
637 variable_pointers_features->variablePointersStorageBuffer;
638 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
639 }
640
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700641 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700642 if (protected_memory_features) {
643 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
644 }
645
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700646 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700647 if (ycbcr_conversion_features) {
648 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
649 }
650
651 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700652 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700653 if (shader_draw_parameters_features) {
654 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700655 }
656 }
657
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700658 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600659 if (device_group_ci) {
660 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
661 state_tracker->device_group_create_info = *device_group_ci;
662 } else {
663 state_tracker->physical_device_count = 1;
664 }
locke-lunargd556cc32019-09-17 01:21:23 -0600665
sfricke-samsung828e59d2021-08-22 23:20:49 -0700666 // Features from other extensions passesd in create info
667 {
668 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
669 if (exclusive_scissor_features) {
670 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
671 }
locke-lunargd556cc32019-09-17 01:21:23 -0600672
sfricke-samsung828e59d2021-08-22 23:20:49 -0700673 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
674 if (shading_rate_image_features) {
675 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
676 }
locke-lunargd556cc32019-09-17 01:21:23 -0600677
sfricke-samsung828e59d2021-08-22 23:20:49 -0700678 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
679 if (mesh_shader_features) {
680 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
681 }
locke-lunargd556cc32019-09-17 01:21:23 -0600682
sfricke-samsung828e59d2021-08-22 23:20:49 -0700683 const auto *inline_uniform_block_features =
684 LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
685 if (inline_uniform_block_features) {
686 state_tracker->enabled_features.inline_uniform_block_features = *inline_uniform_block_features;
687 }
locke-lunargd556cc32019-09-17 01:21:23 -0600688
sfricke-samsung828e59d2021-08-22 23:20:49 -0700689 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
690 if (transform_feedback_features) {
691 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
692 }
locke-lunargd556cc32019-09-17 01:21:23 -0600693
sfricke-samsung828e59d2021-08-22 23:20:49 -0700694 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
695 if (vtx_attrib_div_features) {
696 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
697 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700698
sfricke-samsung828e59d2021-08-22 23:20:49 -0700699 const auto *buffer_device_address_ext_features =
700 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
701 if (buffer_device_address_ext_features) {
702 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
703 }
locke-lunargd556cc32019-09-17 01:21:23 -0600704
sfricke-samsung828e59d2021-08-22 23:20:49 -0700705 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
706 if (cooperative_matrix_features) {
707 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
708 }
locke-lunargd556cc32019-09-17 01:21:23 -0600709
sfricke-samsung828e59d2021-08-22 23:20:49 -0700710 const auto *compute_shader_derivatives_features =
711 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
712 if (compute_shader_derivatives_features) {
713 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
714 }
locke-lunargd556cc32019-09-17 01:21:23 -0600715
sfricke-samsung828e59d2021-08-22 23:20:49 -0700716 const auto *fragment_shader_barycentric_features =
717 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
718 if (fragment_shader_barycentric_features) {
719 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
720 }
locke-lunargd556cc32019-09-17 01:21:23 -0600721
sfricke-samsung828e59d2021-08-22 23:20:49 -0700722 const auto *shader_image_footprint_features =
723 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
724 if (shader_image_footprint_features) {
725 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
726 }
locke-lunargd556cc32019-09-17 01:21:23 -0600727
sfricke-samsung828e59d2021-08-22 23:20:49 -0700728 const auto *fragment_shader_interlock_features =
729 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
730 if (fragment_shader_interlock_features) {
731 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
732 }
locke-lunargd556cc32019-09-17 01:21:23 -0600733
sfricke-samsung828e59d2021-08-22 23:20:49 -0700734 const auto *demote_to_helper_invocation_features =
735 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
736 if (demote_to_helper_invocation_features) {
737 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
738 }
locke-lunargd556cc32019-09-17 01:21:23 -0600739
sfricke-samsung828e59d2021-08-22 23:20:49 -0700740 const auto *texel_buffer_alignment_features =
741 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
742 if (texel_buffer_alignment_features) {
743 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
744 }
locke-lunargd556cc32019-09-17 01:21:23 -0600745
sfricke-samsung828e59d2021-08-22 23:20:49 -0700746 const auto *pipeline_exe_props_features =
747 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
748 if (pipeline_exe_props_features) {
749 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
750 }
locke-lunargd556cc32019-09-17 01:21:23 -0600751
sfricke-samsung828e59d2021-08-22 23:20:49 -0700752 const auto *dedicated_allocation_image_aliasing_features =
753 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
754 if (dedicated_allocation_image_aliasing_features) {
755 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
756 *dedicated_allocation_image_aliasing_features;
757 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500758
sfricke-samsung828e59d2021-08-22 23:20:49 -0700759 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
760 if (performance_query_features) {
761 state_tracker->enabled_features.performance_query_features = *performance_query_features;
762 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100763
sfricke-samsung828e59d2021-08-22 23:20:49 -0700764 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
765 if (device_coherent_memory_features) {
766 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
767 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000768
sfricke-samsung828e59d2021-08-22 23:20:49 -0700769 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
770 if (ycbcr_image_array_features) {
771 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
772 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800773
sfricke-samsung828e59d2021-08-22 23:20:49 -0700774 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
775 if (ray_query_features) {
776 state_tracker->enabled_features.ray_query_features = *ray_query_features;
777 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700778
sfricke-samsung828e59d2021-08-22 23:20:49 -0700779 const auto *ray_tracing_pipeline_features =
780 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
781 if (ray_tracing_pipeline_features) {
782 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
783 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700784
sfricke-samsung828e59d2021-08-22 23:20:49 -0700785 const auto *ray_tracing_acceleration_structure_features =
786 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
787 if (ray_tracing_acceleration_structure_features) {
788 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
789 *ray_tracing_acceleration_structure_features;
790 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500791
sfricke-samsung828e59d2021-08-22 23:20:49 -0700792 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
793 if (robustness2_features) {
794 state_tracker->enabled_features.robustness2_features = *robustness2_features;
795 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500796
sfricke-samsung828e59d2021-08-22 23:20:49 -0700797 const auto *fragment_density_map_features =
798 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
799 if (fragment_density_map_features) {
800 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
801 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200802
sfricke-samsung828e59d2021-08-22 23:20:49 -0700803 const auto *fragment_density_map_features2 =
804 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
805 if (fragment_density_map_features2) {
806 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
807 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200808
sfricke-samsung828e59d2021-08-22 23:20:49 -0700809 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
810 if (astc_decode_features) {
811 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
812 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -0700813
sfricke-samsung828e59d2021-08-22 23:20:49 -0700814 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
815 if (custom_border_color_features) {
816 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
817 }
Tony-LunarG7337b312020-04-15 16:40:25 -0600818
sfricke-samsung828e59d2021-08-22 23:20:49 -0700819 const auto *pipeline_creation_cache_control_features =
820 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
821 if (pipeline_creation_cache_control_features) {
822 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
823 }
sfricke-samsungfd661d62020-05-16 00:57:27 -0700824
sfricke-samsung828e59d2021-08-22 23:20:49 -0700825 const auto *fragment_shading_rate_features =
826 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
827 if (fragment_shading_rate_features) {
828 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
829 }
Tobias Hector6663c9b2020-11-05 10:18:02 +0000830
sfricke-samsung828e59d2021-08-22 23:20:49 -0700831 const auto *extended_dynamic_state_features =
832 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
833 if (extended_dynamic_state_features) {
834 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
835 }
Piers Daniell39842ee2020-07-10 16:42:33 -0600836
sfricke-samsung828e59d2021-08-22 23:20:49 -0700837 const auto *extended_dynamic_state2_features =
838 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
839 if (extended_dynamic_state2_features) {
840 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
841 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -0700842
sfricke-samsung828e59d2021-08-22 23:20:49 -0700843 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
844 if (multiview_features) {
845 state_tracker->enabled_features.multiview_features = *multiview_features;
846 }
locke-lunarg3fa463a2020-10-23 16:39:04 -0600847
sfricke-samsung828e59d2021-08-22 23:20:49 -0700848 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
849 if (portability_features) {
850 state_tracker->enabled_features.portability_subset_features = *portability_features;
851 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -0700852
sfricke-samsung828e59d2021-08-22 23:20:49 -0700853 const auto *shader_integer_functions2_features =
854 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
855 if (shader_integer_functions2_features) {
856 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
857 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800858
sfricke-samsung828e59d2021-08-22 23:20:49 -0700859 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
860 if (shader_sm_builtins_features) {
861 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
862 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800863
sfricke-samsung828e59d2021-08-22 23:20:49 -0700864 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
865 if (shader_atomic_float_features) {
866 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
867 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800868
sfricke-samsung828e59d2021-08-22 23:20:49 -0700869 const auto *shader_image_atomic_int64_features =
870 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
871 if (shader_image_atomic_int64_features) {
872 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
873 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800874
sfricke-samsung828e59d2021-08-22 23:20:49 -0700875 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
876 if (shader_clock_features) {
877 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
878 }
sfricke-samsung486a51e2021-01-02 00:10:15 -0800879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *conditional_rendering_features =
881 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
882 if (conditional_rendering_features) {
883 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
884 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -0700885
sfricke-samsung828e59d2021-08-22 23:20:49 -0700886 const auto *workgroup_memory_explicit_layout_features =
887 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
888 if (workgroup_memory_explicit_layout_features) {
889 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
890 }
Shannon McPhersondb287d42021-02-02 15:27:32 -0700891
sfricke-samsung828e59d2021-08-22 23:20:49 -0700892 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext);
893 if (synchronization2_features) {
894 state_tracker->enabled_features.synchronization2_features = *synchronization2_features;
895 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -0700896
sfricke-samsung828e59d2021-08-22 23:20:49 -0700897 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
898 if (provoking_vertex_features) {
899 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
900 }
Locke Linf3873542021-04-26 11:25:10 -0600901
sfricke-samsung828e59d2021-08-22 23:20:49 -0700902 const auto *vertex_input_dynamic_state_features =
903 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
904 if (vertex_input_dynamic_state_features) {
905 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
906 }
Piers Daniellcb6d8032021-04-19 18:51:26 -0600907
sfricke-samsung828e59d2021-08-22 23:20:49 -0700908 const auto *inherited_viewport_scissor_features =
909 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
910 if (inherited_viewport_scissor_features) {
911 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
912 }
David Zhao Akeley44139b12021-04-26 16:16:13 -0700913
sfricke-samsung828e59d2021-08-22 23:20:49 -0700914 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
915 if (multi_draw_features) {
916 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
917 }
Tony-LunarG4490de42021-06-21 15:49:19 -0600918
sfricke-samsung828e59d2021-08-22 23:20:49 -0700919 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
920 if (color_write_features) {
921 state_tracker->enabled_features.color_write_features = *color_write_features;
922 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +0200923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *shader_atomic_float2_features =
925 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
926 if (shader_atomic_float2_features) {
927 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
928 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -0700929
sfricke-samsung828e59d2021-08-22 23:20:49 -0700930 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
931 if (present_id_features) {
932 state_tracker->enabled_features.present_id_features = *present_id_features;
933 }
Tony-LunarG6f887e52021-07-27 11:23:14 -0600934
sfricke-samsung828e59d2021-08-22 23:20:49 -0700935 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
936 if (present_wait_features) {
937 state_tracker->enabled_features.present_wait_features = *present_wait_features;
938 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -0700939
940 const auto *ray_tracing_motion_blur_features =
941 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
942 if (ray_tracing_motion_blur_features) {
943 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
944 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -0700945
946 const auto *shader_integer_dot_product_features =
947 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
948 if (shader_integer_dot_product_features) {
949 state_tracker->enabled_features.shader_integer_dot_product_features = *shader_integer_dot_product_features;
950 }
Tony-LunarG0b0d8be2021-08-30 13:50:38 -0600951
952 const auto *primitive_topology_list_restart_features =
953 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
954 if (primitive_topology_list_restart_features) {
955 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
956 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -0700957
958 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
959 if (rgba10x6_formats_features) {
960 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
961 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -0700962
963 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
964 if (maintenance4_features) {
965 state_tracker->enabled_features.maintenance4_features = *maintenance4_features;
966 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -0700967
968 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(pCreateInfo->pNext);
969 if (dynamic_rendering_features) {
970 state_tracker->enabled_features.dynamic_rendering_features = *dynamic_rendering_features;
971 }
Tony-LunarG69604c42021-11-22 16:00:12 -0700972
973 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
974 if (image_view_min_lod_features) {
975 state_tracker->enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
976 }
Tony-LunarG6f887e52021-07-27 11:23:14 -0600977 }
978
ziga-lunarg73163742021-08-25 13:15:29 +0200979 const auto *subgroup_size_control_features = LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeaturesEXT>(pCreateInfo->pNext);
980 if (subgroup_size_control_features) {
981 state_tracker->enabled_features.subgroup_size_control_features = *subgroup_size_control_features;
982 }
983
locke-lunargd556cc32019-09-17 01:21:23 -0600984 // Store physical device properties and physical device mem limits into CoreChecks structs
985 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
986 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
987
988 const auto &dev_ext = state_tracker->device_extensions;
989 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
990
sfricke-samsung828e59d2021-08-22 23:20:49 -0700991 // Vulkan 1.2 can get properties from single struct, otherwise need to add to it per extension
sfricke-samsung45996a42021-09-16 13:45:27 -0700992 if (dev_ext.vk_feature_version_1_2) {
993 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
994 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
sfricke-samsung828e59d2021-08-22 23:20:49 -0700995 } else {
996 // VkPhysicalDeviceVulkan11Properties
997 //
998 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
999
1000 if (dev_ext.vk_khr_multiview) {
1001 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1002 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1003 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1004 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1005 }
1006
1007 if (dev_ext.vk_khr_maintenance3) {
1008 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1009 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1010 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1011 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1012 }
1013
1014 // Some 1.1 properties were added to core without previous extensions
1015 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1016 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1017 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1018 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1019 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1020
1021 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1022 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1023 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1024 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1025
1026 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1027 }
1028
1029 // VkPhysicalDeviceVulkan12Properties
1030 //
1031 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1032
1033 if (dev_ext.vk_ext_descriptor_indexing) {
1034 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1035 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1036 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1037 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1038 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1039 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1040 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1041 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1042 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1043 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1044 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1045 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1046 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1047 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1048 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1049 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1050 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1051 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1052 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1053 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1054 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1055 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1056 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1057 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1058 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1059 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1060 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1061 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1062 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1063 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1064 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1065 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1066 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1067 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1068 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1069 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1070 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1071 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1072 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1073 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1074 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1075 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1076 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1077 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1078 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1079 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1080 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1081 }
1082
1083 if (dev_ext.vk_khr_depth_stencil_resolve) {
1084 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1085 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1086 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1087 depth_stencil_resolve_props.supportedDepthResolveModes;
1088 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1089 depth_stencil_resolve_props.supportedStencilResolveModes;
1090 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1091 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1092 }
1093
1094 if (dev_ext.vk_khr_timeline_semaphore) {
1095 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1096 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1097 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1098 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1099 }
1100
1101 if (dev_ext.vk_ext_sampler_filter_minmax) {
1102 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1103 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1104 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1105 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1106 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1107 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1108 }
1109
1110 if (dev_ext.vk_khr_shader_float_controls) {
1111 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1112 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1113 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1114 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1115 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1116 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1117 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1118 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1119 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1120 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1121 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1122 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1123 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1124 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1125 float_controls_props.shaderDenormFlushToZeroFloat16;
1126 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1127 float_controls_props.shaderDenormFlushToZeroFloat32;
1128 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1129 float_controls_props.shaderDenormFlushToZeroFloat64;
1130 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1131 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1132 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1133 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1134 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1135 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1136 }
locke-lunargd556cc32019-09-17 01:21:23 -06001137 }
1138
sfricke-samsung828e59d2021-08-22 23:20:49 -07001139 // Extensions with properties to extract to DeviceExtensionProperties
1140 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001141 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1142 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1143 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1144 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001145 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001146 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001147 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1148 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001149 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1150 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001151 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001152 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001153 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001154 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001155 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001156 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001157 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001158 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001159 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001160 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001161 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001162 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001163 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001164
sfricke-samsung45996a42021-09-16 13:45:27 -07001165 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001166 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001167 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1168 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001169 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1170 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1171
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001172 uint32_t num_cooperative_matrix_properties = 0;
1173 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1174 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001175 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001176
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001177 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001178 state_tracker->cooperative_matrix_properties.data());
1179 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001180
locke-lunargd556cc32019-09-17 01:21:23 -06001181 // Store queue family data
1182 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1183 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001184 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001185 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1186 state_tracker->device_queue_info_list.push_back(
1187 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001188 }
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001189 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1190 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1191 VkQueue queue = VK_NULL_HANDLE;
1192 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1193 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1194 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1195 get_info.flags = queue_info.flags;
1196 get_info.queueFamilyIndex = queue_info.queue_family_index;
1197 get_info.queueIndex = i;
1198 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1199 } else {
1200 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1201 }
1202 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001203 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001204 }
locke-lunargd556cc32019-09-17 01:21:23 -06001205 }
1206 }
1207}
1208
1209void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1210 if (!device) return;
1211
Jeremy Gebbend177d922021-10-28 13:42:10 -06001212 command_pool_map_.clear();
1213 assert(command_buffer_map_.empty());
1214 pipeline_map_.clear();
1215 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001216
1217 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001218 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001219 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001220 assert(descriptor_set_map_.empty());
1221 desc_template_map_.clear();
1222 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001223 // Because swapchains are associated with Surfaces, which are at instance level,
1224 // they need to be explicitly destroyed here to avoid continued references to
1225 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001226 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001227 entry.second->Destroy();
1228 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001229 swapchain_map_.clear();
1230 image_view_map_.clear();
1231 image_map_.clear();
1232 buffer_view_map_.clear();
1233 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001234 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001235 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001236}
1237
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001238void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1239 VkFence fence, VkResult result) {
1240 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001241 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001242
Jeremy Gebben57642982021-09-14 14:14:55 -06001243 uint64_t early_retire_seq = 0;
1244
1245 if (submitCount == 0) {
1246 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001247 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001248 early_retire_seq = queue_state->Submit(std::move(submission));
1249 }
locke-lunargd556cc32019-09-17 01:21:23 -06001250
1251 // Now process each individual submit
1252 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001253 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001254 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001255 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001256 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001257 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001258 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1259 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1260 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1261 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001262 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001263 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001264
locke-lunargd556cc32019-09-17 01:21:23 -06001265 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001266 uint64_t value{0};
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001267 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1268 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1269 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1270 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001271 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001272 }
1273
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001274 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001275 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001276
locke-lunargd556cc32019-09-17 01:21:23 -06001277 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001278 submission.AddCommandBuffer(Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001279 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001280 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001281 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001282 }
1283 auto submit_seq = queue_state->Submit(std::move(submission));
1284 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001285 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001286
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001287 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001288 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001289 }
1290}
1291
1292void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1293 VkFence fence, VkResult result) {
1294 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001295 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001296 uint64_t early_retire_seq = 0;
1297 if (submitCount == 0) {
1298 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001299 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001300 early_retire_seq = queue_state->Submit(std::move(submission));
1301 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001302
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001303 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1304 CB_SUBMISSION submission;
1305 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001306 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1307 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001308 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001309 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001310 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1311 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001312 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001313 }
1314 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1315 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1316
1317 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001318 submission.AddCommandBuffer(Get<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001319 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001320 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001321 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001322 }
1323 auto submit_seq = queue_state->Submit(std::move(submission));
1324 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001325 }
locke-lunargd556cc32019-09-17 01:21:23 -06001326 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001327 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001328 }
1329}
1330
1331void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1332 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1333 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001334 if (VK_SUCCESS != result) {
1335 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001336 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001337 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1338 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1339 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1340
1341 layer_data::optional<DedicatedBinding> dedicated_binding;
1342
1343 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1344 if (dedicated) {
1345 if (dedicated->buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001346 const auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001347 assert(buffer_state);
1348 if (!buffer_state) {
1349 return;
1350 }
1351 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1352 } else if (dedicated->image) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001353 const auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001354 assert(image_state);
1355 if (!image_state) {
1356 return;
1357 }
1358 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1359 }
1360 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001361 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1362 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001363 return;
1364}
1365
1366void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001367 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001368 if (mem_info) {
1369 fake_memory.Free(mem_info->fake_base_address);
1370 }
1371 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001372}
1373
1374void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1375 VkFence fence, VkResult result) {
1376 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001377 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001378
Jeremy Gebben57642982021-09-14 14:14:55 -06001379 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001380
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001381 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1382 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001383 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001384 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1385 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1386 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001387 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001388 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001389 if (buffer_state && mem_state) {
1390 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1391 }
locke-lunargd556cc32019-09-17 01:21:23 -06001392 }
1393 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001394 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1395 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1396 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001397 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001398 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001399 if (image_state && mem_state) {
1400 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1401 }
locke-lunargd556cc32019-09-17 01:21:23 -06001402 }
1403 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001404 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1405 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1406 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001407 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1408 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001409 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001410 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001411 if (image_state && mem_state) {
1412 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1413 }
locke-lunargd556cc32019-09-17 01:21:23 -06001414 }
1415 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001416 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001417 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001418 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001419 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001420 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001421 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001422 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001423 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001424 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001425 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001426 auto submit_seq = queue_state->Submit(std::move(submission));
1427 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001428 }
1429
1430 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001431 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001432 }
1433}
1434
1435void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1436 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1437 VkResult result) {
1438 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001439 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001440}
1441
Mike Schuchardt2df08912020-12-15 16:28:09 -08001442void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1443 VkSemaphoreImportFlags flags) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001444 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
1445 if (semaphore_state) {
1446 semaphore_state->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001447 }
1448}
1449
Mike Schuchardt2df08912020-12-15 16:28:09 -08001450void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001451 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001452 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07001453 if (semaphore_state) {
1454 semaphore_state->RetireTimeline(pSignalInfo->value);
1455 }
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001456}
1457
locke-lunargd556cc32019-09-17 01:21:23 -06001458void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001459 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001460 if (mem_info) {
1461 mem_info->mapped_range.offset = offset;
1462 mem_info->mapped_range.size = size;
1463 mem_info->p_driver_data = *ppData;
1464 }
1465}
1466
locke-lunargd556cc32019-09-17 01:21:23 -06001467void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1468 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1469 if (VK_SUCCESS != result) return;
1470
1471 // When we know that all fences are complete we can clean/remove their CBs
1472 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1473 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001474 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001475 if (fence_state) {
1476 fence_state->Retire();
1477 }
locke-lunargd556cc32019-09-17 01:21:23 -06001478 }
1479 }
1480 // NOTE : Alternate case not handled here is when some fences have completed. In
1481 // this case for app to guarantee which fences completed it will have to call
1482 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1483}
1484
John Zulauff89de662020-04-13 18:57:34 -06001485void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1486 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001487 if (VK_SUCCESS != result) return;
1488
Jeremy Gebben15332642021-12-15 19:33:15 -07001489 // Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
1490 // the application calls vkGetSemaphoreCounterValue() on each of them.
1491 if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
1492 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1493 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
1494 if (semaphore_state) {
1495 semaphore_state->RetireTimeline(pWaitInfo->pValues[i]);
1496 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001497 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001498 }
1499}
1500
John Zulauff89de662020-04-13 18:57:34 -06001501void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1502 VkResult result) {
1503 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1504}
1505
1506void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1507 uint64_t timeout, VkResult result) {
1508 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1509}
1510
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001511void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1512 VkResult result) {
1513 if (VK_SUCCESS != result) return;
1514
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001515 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001516 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07001517 semaphore_state->RetireTimeline(*pValue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001518 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001519}
1520
1521void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1522 VkResult result) {
1523 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1524}
1525void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1526 VkResult result) {
1527 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1528}
1529
locke-lunargd556cc32019-09-17 01:21:23 -06001530void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1531 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001532 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001533 if (fence_state) {
1534 fence_state->Retire();
1535 }
locke-lunargd556cc32019-09-17 01:21:23 -06001536}
1537
Yilong Lice03a312022-01-02 02:08:35 -08001538void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1539 if (Get<QUEUE_STATE>(queue) == nullptr) {
1540 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1541 }
1542}
1543
1544void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1545 VkQueue *pQueue) {
1546 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1547}
1548
1549void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1550 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1551}
1552
locke-lunargd556cc32019-09-17 01:21:23 -06001553void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1554 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001555 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001556 if (queue_state) {
1557 queue_state->Retire();
1558 }
locke-lunargd556cc32019-09-17 01:21:23 -06001559}
1560
1561void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1562 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001563 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001564 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001565 }
1566}
1567
1568void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001569 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001570}
1571
1572void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1573 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001574 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001575}
1576
1577void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001578 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001579}
1580
1581void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1582 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001583 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001584}
1585
locke-lunargd556cc32019-09-17 01:21:23 -06001586void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001587 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001588 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001589 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001590 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001591 if (mem_state) {
1592 buffer_state->SetMemBinding(mem_state, memoryOffset);
1593 }
locke-lunargd556cc32019-09-17 01:21:23 -06001594 }
1595}
1596
1597void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1598 VkDeviceSize memoryOffset, VkResult result) {
1599 if (VK_SUCCESS != result) return;
1600 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1601}
1602
1603void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001604 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001605 for (uint32_t i = 0; i < bindInfoCount; i++) {
1606 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1607 }
1608}
1609
1610void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001611 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001612 for (uint32_t i = 0; i < bindInfoCount; i++) {
1613 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1614 }
1615}
1616
Spencer Fricke6c127102020-04-16 06:25:20 -07001617void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001618 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001619 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001620 buffer_state->memory_requirements_checked = true;
1621 }
1622}
1623
1624void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1625 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001626 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001627}
1628
1629void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001630 const VkBufferMemoryRequirementsInfo2 *pInfo,
1631 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001632 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001633}
1634
1635void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001636 const VkBufferMemoryRequirementsInfo2 *pInfo,
1637 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001638 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001639}
1640
Spencer Fricke6c127102020-04-16 06:25:20 -07001641void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001642 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001643 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001644 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001645 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001646 if (plane_info != nullptr) {
1647 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001648 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001649 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001650 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001651 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001652 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001653 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001654 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001655 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001656 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001657 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001658 }
locke-lunargd556cc32019-09-17 01:21:23 -06001659 }
1660}
1661
1662void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1663 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001664 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001665}
1666
1667void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1668 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001669 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001670}
1671
1672void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1673 const VkImageMemoryRequirementsInfo2 *pInfo,
1674 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001675 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001676}
1677
locke-lunargd556cc32019-09-17 01:21:23 -06001678void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1679 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1680 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001681 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001682 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001683}
1684
1685void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001686 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1687 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001688 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001689 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001690}
1691
1692void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001693 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1694 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001695 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001696 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001697}
1698
1699void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1700 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001701 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001702}
1703
1704void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1705 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001706 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001707}
1708
1709void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1710 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001711 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001712}
1713
1714void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1715 const VkAllocationCallbacks *pAllocator) {
1716 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001717 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001718 // Any bound cmd buffers are now invalid
1719 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001720 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1721 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1722 custom_border_color_sampler_count--;
1723 }
locke-lunargd556cc32019-09-17 01:21:23 -06001724 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001725 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001726}
1727
1728void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1729 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001730 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001731}
1732
1733void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1734 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001735 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001736}
1737
locke-lunargd556cc32019-09-17 01:21:23 -06001738void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1739 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001740 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1741 if (pool) {
1742 pool->Free(commandBufferCount, pCommandBuffers);
1743 }
locke-lunargd556cc32019-09-17 01:21:23 -06001744}
1745
1746void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1747 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1748 VkResult result) {
1749 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001750 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001751 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001752}
1753
1754void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1755 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1756 VkResult result) {
1757 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001758
1759 uint32_t index_count = 0, n_perf_pass = 0;
1760 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001761 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001762 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001763 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001764
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001765 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001766 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1767 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1768 switch (counter.scope) {
1769 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001770 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001771 break;
1772 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001773 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001774 break;
1775 default:
1776 break;
1777 }
1778 }
1779
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001780 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001781 }
1782
Jeremy Gebben082a9832021-10-28 13:40:11 -06001783 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 -06001784
locke-lunargd556cc32019-09-17 01:21:23 -06001785}
1786
1787void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1788 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001789 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001790}
1791
1792void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
1793 VkCommandPoolResetFlags flags, VkResult result) {
1794 if (VK_SUCCESS != result) return;
1795 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001796 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1797 if (pool) {
1798 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001799 }
1800}
1801
1802void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1803 VkResult result) {
1804 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001805 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001806 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07001807 fence_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001808 }
1809 }
1810}
1811
locke-lunargd556cc32019-09-17 01:21:23 -06001812void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
1813 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001814 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001815}
1816
1817void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
1818 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001819 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06001820}
1821
1822void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
1823 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
1824 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001825 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001826}
1827
1828bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1829 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1830 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001831 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001832 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
1833 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1834 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1835 cgpl_state->pipe_state.reserve(count);
1836 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebbence23dac2021-11-10 10:19:42 -07001837 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001838 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
1839 Get<RENDER_PASS_STATE>(pCreateInfos[i].renderPass),
1840 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
amhagana448ea52021-11-02 14:09:14 -04001841 } else if (enabled_features.dynamic_rendering_features.dynamicRendering) {
1842 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfoKHR>(pCreateInfos[i].pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001843 cgpl_state->pipe_state.push_back(
1844 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], std::make_shared<RENDER_PASS_STATE>(dynamic_rendering),
Jeremy Gebben9f537102021-10-05 16:37:12 -06001845 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeremy Gebbence23dac2021-11-10 10:19:42 -07001846 }
locke-lunargd556cc32019-09-17 01:21:23 -06001847 }
1848 return false;
1849}
1850
1851void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1852 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1853 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
1854 VkResult result, void *cgpl_state_data) {
1855 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1856 // This API may create pipelines regardless of the return value
1857 for (uint32_t i = 0; i < count; i++) {
1858 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001859 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001860 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001861 }
1862 }
1863 cgpl_state->pipe_state.clear();
1864}
1865
1866bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1867 const VkComputePipelineCreateInfo *pCreateInfos,
1868 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001869 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001870 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
1871 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1872 ccpl_state->pipe_state.reserve(count);
1873 for (uint32_t i = 0; i < count; i++) {
1874 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001875 ccpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06001876 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06001877 }
1878 return false;
1879}
1880
1881void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1882 const VkComputePipelineCreateInfo *pCreateInfos,
1883 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
1884 VkResult result, void *ccpl_state_data) {
1885 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
1886
1887 // This API may create pipelines regardless of the return value
1888 for (uint32_t i = 0; i < count; i++) {
1889 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001890 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001891 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001892 }
1893 }
1894 ccpl_state->pipe_state.clear();
1895}
1896
1897bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
1898 uint32_t count,
1899 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1900 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001901 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001902 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
1903 crtpl_state->pipe_state.reserve(count);
1904 for (uint32_t i = 0; i < count; i++) {
1905 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001906 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06001907 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06001908 }
1909 return false;
1910}
1911
1912void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
1913 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1914 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
1915 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
1916 // This API may create pipelines regardless of the return value
1917 for (uint32_t i = 0; i < count; i++) {
1918 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001919 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001920 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001921 }
1922 }
1923 crtpl_state->pipe_state.clear();
1924}
1925
sourav parmarcd5fb182020-07-17 12:58:44 -07001926bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
1927 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001928 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
1929 const VkAllocationCallbacks *pAllocator,
1930 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001931 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001932 crtpl_state->pipe_state.reserve(count);
1933 for (uint32_t i = 0; i < count; i++) {
1934 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001935 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06001936 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001937 }
1938 return false;
1939}
1940
sourav parmarcd5fb182020-07-17 12:58:44 -07001941void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
1942 VkPipelineCache pipelineCache, uint32_t count,
1943 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
1944 const VkAllocationCallbacks *pAllocator,
1945 VkPipeline *pPipelines, VkResult result,
1946 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001947 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
1948 // This API may create pipelines regardless of the return value
1949 for (uint32_t i = 0; i < count; i++) {
1950 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001951 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001952 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001953 }
1954 }
1955 crtpl_state->pipe_state.clear();
1956}
1957
locke-lunargd556cc32019-09-17 01:21:23 -06001958void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
1959 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
1960 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001961 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001962 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1963 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06001964 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001965 }
locke-lunargd556cc32019-09-17 01:21:23 -06001966}
1967
1968void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
1969 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1970 const VkAllocationCallbacks *pAllocator,
1971 VkDescriptorSetLayout *pSetLayout, VkResult result) {
1972 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001973 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06001974}
1975
locke-lunargd556cc32019-09-17 01:21:23 -06001976void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
1977 const VkAllocationCallbacks *pAllocator,
1978 VkPipelineLayout *pPipelineLayout, VkResult result) {
1979 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001980 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001981}
1982
1983void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
1984 const VkAllocationCallbacks *pAllocator,
1985 VkDescriptorPool *pDescriptorPool, VkResult result) {
1986 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001987 Add(std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001988}
1989
1990void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1991 VkDescriptorPoolResetFlags flags, VkResult result) {
1992 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06001993 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
1994 if (pool) {
1995 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001996 }
locke-lunargd556cc32019-09-17 01:21:23 -06001997}
1998
1999bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2000 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002001 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002002 // Always update common data
2003 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2004 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2005 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2006
2007 return false;
2008}
2009
2010// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2011void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2012 VkDescriptorSet *pDescriptorSets, VkResult result,
2013 void *ads_state_data) {
2014 if (VK_SUCCESS != result) return;
2015 // All the updates are contained in a single cvdescriptorset function
2016 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2017 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002018 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2019 if (pool_state) {
2020 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2021 }
locke-lunargd556cc32019-09-17 01:21:23 -06002022}
2023
2024void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2025 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002026 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2027 if (pool_state) {
2028 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002029 }
2030}
2031
2032void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2033 const VkWriteDescriptorSet *pDescriptorWrites,
2034 uint32_t descriptorCopyCount,
2035 const VkCopyDescriptorSet *pDescriptorCopies) {
2036 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2037 pDescriptorCopies);
2038}
2039
2040void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002041 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002042 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002043 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002044 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002045 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002046 }
2047}
2048
locke-lunargd556cc32019-09-17 01:21:23 -06002049void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2050 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002051 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002052 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002053
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002054 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002055}
2056
2057void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002058 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002059 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002060
2061 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002062}
2063
2064void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2065 VkResult result) {
2066 if (VK_SUCCESS == result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002067 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002068 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002069 }
2070}
2071
2072CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2073 // initially assume everything is static state
2074 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2075
2076 if (ds) {
2077 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002078 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002079 }
2080 }
locke-lunargd556cc32019-09-17 01:21:23 -06002081 return flags;
2082}
2083
2084// Validation cache:
2085// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002086
2087void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2088 VkPipeline pipeline) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002089 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002090 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002091 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002092
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002093 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002094 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002095 const auto &create_info = pipe_state->create_info.graphics;
2096 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2097 const auto *viewport_state = create_info.pViewportState;
2098 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002099 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002100 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002101 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002102 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002103
2104 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002105 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2106 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002107 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002108 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002109 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002110 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002111 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002112 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002113
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002114 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002115 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2116 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2117 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002118 if (!has_dynamic_viewport_count) {
2119 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002120 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002121 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2122 // should become = ~uint32_t(0) if the other interpretation is correct.
2123 }
2124 }
2125 if (!has_dynamic_scissor_count) {
2126 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002127 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002128 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2129 // should become = ~uint32_t(0) if the other interpretation is correct.
2130 }
2131 }
locke-lunargd556cc32019-09-17 01:21:23 -06002132 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002133 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002134 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002135 if (!disabled[command_buffer_state]) {
2136 cb_state->AddChild(pipe_state);
2137 }
locke-lunargd556cc32019-09-17 01:21:23 -06002138}
2139
2140void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2141 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002142 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002143 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002144 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2145 cb_state->viewportMask |= bits;
2146 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002147
2148 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2149 for (size_t i = 0; i < viewportCount; ++i) {
2150 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2151 }
locke-lunargd556cc32019-09-17 01:21:23 -06002152}
2153
2154void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2155 uint32_t exclusiveScissorCount,
2156 const VkRect2D *pExclusiveScissors) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002157 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002158 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002159 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2160 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002161}
2162
2163void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2164 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002165 if (disabled[command_buffer_state]) return;
2166
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002167 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002168 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002169
2170 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002171 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002172 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002173 }
2174}
2175
2176void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2177 uint32_t viewportCount,
2178 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002179 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002180 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002181 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2182 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002183}
2184
2185void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2186 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2187 const VkAllocationCallbacks *pAllocator,
2188 VkAccelerationStructureNV *pAccelerationStructure,
2189 VkResult result) {
2190 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002191 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002192
2193 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002194 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002195 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002196 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002197 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2198
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002199 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002200 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002201 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002202 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2203 &as_state->build_scratch_memory_requirements);
2204
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002205 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002206 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002207 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002208 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2209 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002210 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002211 Add(std::move(as_state));
locke-lunargd556cc32019-09-17 01:21:23 -06002212}
2213
Jeff Bolz95176d02020-04-01 00:36:16 -05002214void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2215 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2216 const VkAllocationCallbacks *pAllocator,
2217 VkAccelerationStructureKHR *pAccelerationStructure,
2218 VkResult result) {
2219 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002220 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002221 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002222 Add(std::move(as_state));
Jeff Bolz95176d02020-04-01 00:36:16 -05002223}
2224
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002225void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2226 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2227 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2228 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2229 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002230 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002231 if (dst_as_state != nullptr) {
2232 dst_as_state->Build(&pInfos[i]);
2233 }
2234 }
2235}
2236
sourav parmarcd5fb182020-07-17 12:58:44 -07002237void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2238 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2239 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002240 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002241 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002242 return;
2243 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002244 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002245 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002246 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002247 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002248 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002249 if (!disabled[command_buffer_state]) {
2250 cb_state->AddChild(dst_as_state);
2251 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002252 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002253 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002254 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002255 if (src_as_state != nullptr) {
2256 cb_state->AddChild(src_as_state);
2257 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002258 }
2259 }
2260 cb_state->hasBuildAccelerationStructureCmd = true;
2261}
2262
2263void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2264 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2265 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2266 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002267 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002268 if (cb_state == nullptr) {
2269 return;
2270 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002271 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002272 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002273 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002274 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002275 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002276 if (!disabled[command_buffer_state]) {
2277 cb_state->AddChild(dst_as_state);
2278 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002279 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002280 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002281 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002282 if (src_as_state != nullptr) {
2283 cb_state->AddChild(src_as_state);
2284 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002285 }
2286 }
2287 cb_state->hasBuildAccelerationStructureCmd = true;
2288}
locke-lunargd556cc32019-09-17 01:21:23 -06002289void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002290 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002291 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002292 if (as_state != nullptr) {
2293 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2294 as_state->memory_requirements = *pMemoryRequirements;
2295 as_state->memory_requirements_checked = true;
2296 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2297 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2298 as_state->build_scratch_memory_requirements_checked = true;
2299 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2300 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2301 as_state->update_scratch_memory_requirements_checked = true;
2302 }
2303 }
2304}
2305
sourav parmarcd5fb182020-07-17 12:58:44 -07002306void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2307 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002308 if (VK_SUCCESS != result) return;
2309 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002310 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002311
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002312 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002313 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002314 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002315 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002316 if (mem_state) {
2317 as_state->SetMemBinding(mem_state, info.memoryOffset);
2318 }
locke-lunargd556cc32019-09-17 01:21:23 -06002319
2320 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002321 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002322 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002323 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2324 }
2325 }
2326 }
2327}
2328
2329void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2330 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2331 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002332 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002333 if (cb_state == nullptr) {
2334 return;
2335 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002336 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002337
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002338 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002339 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002340 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002341 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002342 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002343 }
locke-lunargd556cc32019-09-17 01:21:23 -06002344 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002345 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002346 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002347 if (src_as_state != nullptr) {
2348 cb_state->AddChild(src_as_state);
2349 }
locke-lunargd556cc32019-09-17 01:21:23 -06002350 }
2351 cb_state->hasBuildAccelerationStructureCmd = true;
2352}
2353
2354void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2355 VkAccelerationStructureNV dst,
2356 VkAccelerationStructureNV src,
2357 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002358 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002359 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002360 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2361 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002362 if (!disabled[command_buffer_state]) {
2363 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2364 }
locke-lunargd556cc32019-09-17 01:21:23 -06002365 if (dst_as_state != nullptr && src_as_state != nullptr) {
2366 dst_as_state->built = true;
2367 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002368 }
2369 }
2370}
2371
Jeff Bolz95176d02020-04-01 00:36:16 -05002372void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2373 VkAccelerationStructureKHR accelerationStructure,
2374 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002375 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002376}
2377
Jeff Bolz95176d02020-04-01 00:36:16 -05002378void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2379 VkAccelerationStructureNV accelerationStructure,
2380 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002381 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002382}
2383
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002384void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2385 uint32_t viewportCount,
2386 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002387 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002388 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002389}
2390
locke-lunargd556cc32019-09-17 01:21:23 -06002391void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002392 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002393 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002394}
2395
2396void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2397 uint16_t lineStipplePattern) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002398 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002399 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002400}
2401
2402void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2403 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002404 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002405 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002406}
2407
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002408void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2409 const VkRect2D *pScissors) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002410 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002411 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002412 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2413 cb_state->scissorMask |= bits;
2414 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002415}
2416
locke-lunargd556cc32019-09-17 01:21:23 -06002417void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002418 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002419 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002420}
2421
2422void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2423 float maxDepthBounds) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002424 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002425 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002426}
2427
2428void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2429 uint32_t compareMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002430 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002431 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002432}
2433
2434void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2435 uint32_t writeMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002436 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002437 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002438}
2439
2440void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2441 uint32_t reference) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002442 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002443 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002444}
2445
locke-lunargd556cc32019-09-17 01:21:23 -06002446// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2447void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2448 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2449 uint32_t firstSet, uint32_t setCount,
2450 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2451 const uint32_t *pDynamicOffsets) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002452 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002453 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002454 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
locke-lunargd556cc32019-09-17 01:21:23 -06002455
Jeremy Gebben9f537102021-10-05 16:37:12 -06002456 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets, nullptr,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002457 dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002458}
2459
locke-lunargd556cc32019-09-17 01:21:23 -06002460void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2461 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2462 uint32_t set, uint32_t descriptorWriteCount,
2463 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002464 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2465 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002466 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002467}
2468
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002469void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2470 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2471 const void *pValues) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002472 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002473 if (cb_state != nullptr) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002474 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002475 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2476 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002477
2478 auto &push_constant_data = cb_state->push_constant_data;
2479 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2480 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002481 cb_state->push_constant_pipeline_layout_set = layout;
2482
2483 auto flags = stageFlags;
2484 uint32_t bit_shift = 0;
2485 while (flags) {
2486 if (flags & 1) {
2487 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2488 const auto it = cb_state->push_constant_data_update.find(flag);
2489
2490 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002491 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002492 }
2493 }
2494 flags = flags >> 1;
2495 ++bit_shift;
2496 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002497 }
2498}
2499
locke-lunargd556cc32019-09-17 01:21:23 -06002500void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2501 VkIndexType indexType) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002502 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002503
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002504 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002505 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002506 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002507 cb_state->index_buffer_binding.offset = offset;
2508 cb_state->index_buffer_binding.index_type = indexType;
2509 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002510 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002511 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002512 }
locke-lunargd556cc32019-09-17 01:21:23 -06002513}
2514
2515void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2516 uint32_t bindingCount, const VkBuffer *pBuffers,
2517 const VkDeviceSize *pOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002518 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002519 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002520
2521 uint32_t end = firstBinding + bindingCount;
2522 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2523 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2524 }
2525
2526 for (uint32_t i = 0; i < bindingCount; ++i) {
2527 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002528 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002529 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002530 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2531 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002532 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002533 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002534 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002535 }
locke-lunargd556cc32019-09-17 01:21:23 -06002536 }
2537}
2538
2539void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2540 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002541 if (disabled[command_buffer_state]) return;
2542
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002543 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002544 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002545}
2546
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002547void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2548 VkPipelineStageFlags stageMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002549 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002550 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002551}
2552
2553void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2554 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002555 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002556 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2557
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002558 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2559 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002560}
2561
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002562void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2563 VkPipelineStageFlags stageMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002564 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002565 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002566}
2567
2568void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2569 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002570 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002571 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002572}
2573
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002574void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2575 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2576 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2577 uint32_t bufferMemoryBarrierCount,
2578 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2579 uint32_t imageMemoryBarrierCount,
2580 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002581 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002582 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
2583 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2584 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002585}
2586
2587void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2588 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002589 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002590 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
Jeremy Gebben79649152021-06-22 14:46:24 -06002591 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002592 cb_state->RecordBarriers(pDependencyInfos[i]);
Jeremy Gebben79649152021-06-22 14:46:24 -06002593 }
2594}
2595
2596void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2597 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2598 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2599 uint32_t bufferMemoryBarrierCount,
2600 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2601 uint32_t imageMemoryBarrierCount,
2602 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002603 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2604 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2605 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2606 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002607}
2608
2609void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2610 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002611 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2612 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2613 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002614}
2615
locke-lunargd556cc32019-09-17 01:21:23 -06002616void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2617 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002618 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002619
locke-lunargd556cc32019-09-17 01:21:23 -06002620 QueryObject query = {queryPool, slot};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002621 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002622 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002623 if (!disabled[query_validation]) {
2624 cb_state->BeginQuery(query);
2625 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002626 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002627 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002628 cb_state->AddChild(pool_state);
2629 }
locke-lunargd556cc32019-09-17 01:21:23 -06002630}
2631
2632void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002633 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002634 QueryObject query_obj = {queryPool, slot};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002635 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002636 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002637 if (!disabled[query_validation]) {
2638 cb_state->EndQuery(query_obj);
2639 }
2640 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002641 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002642 cb_state->AddChild(pool_state);
2643 }
locke-lunargd556cc32019-09-17 01:21:23 -06002644}
2645
2646void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2647 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002648 if (disabled[query_validation]) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002649 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002650
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002651 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002652 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002653
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002654 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002655 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002656 cb_state->AddChild(pool_state);
2657 }
locke-lunargd556cc32019-09-17 01:21:23 -06002658}
2659
2660void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2661 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2662 VkDeviceSize dstOffset, VkDeviceSize stride,
2663 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002664 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2665
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002666 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002667 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002668 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002669 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002670 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002671 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002672}
2673
2674void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2675 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002676 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002677 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002678}
2679
2680void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2681 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2682 uint32_t slot) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002683 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002684 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002685}
2686
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002687void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
2688 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
2689 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
2690 if (disabled[query_validation]) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002691 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002692 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002693 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002694 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002695 cb_state->AddChild(pool_state);
2696 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002697 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002698}
2699
locke-lunargd556cc32019-09-17 01:21:23 -06002700void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
2701 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
2702 VkResult result) {
2703 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002704
Jeremy Gebben88f58142021-06-01 10:07:52 -06002705 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002706 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002707 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002708
locke-lunargd556cc32019-09-17 01:21:23 -06002709 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002710 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002711 }
2712 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06002713
Jeremy Gebben9f537102021-10-05 16:37:12 -06002714 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06002715 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06002716}
2717
locke-lunargd556cc32019-09-17 01:21:23 -06002718void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
2719 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2720 VkResult result) {
2721 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002722 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002723}
2724
Mike Schuchardt2df08912020-12-15 16:28:09 -08002725void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002726 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2727 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002728 if (VK_SUCCESS != result) return;
2729
Jeremy Gebben082a9832021-10-28 13:40:11 -06002730 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002731}
2732
Mike Schuchardt2df08912020-12-15 16:28:09 -08002733void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002734 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2735 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002736 if (VK_SUCCESS != result) return;
2737
Jeremy Gebben082a9832021-10-28 13:40:11 -06002738 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002739}
2740
locke-lunargd556cc32019-09-17 01:21:23 -06002741void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
2742 const VkRenderPassBeginInfo *pRenderPassBegin,
2743 VkSubpassContents contents) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002744 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002745 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002746}
2747
2748void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
2749 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002750 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002751 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002752 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002753}
2754
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002755void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2756 uint32_t counterBufferCount,
2757 const VkBuffer *pCounterBuffers,
2758 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002759 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002760
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002761 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002762 cb_state->transform_feedback_active = true;
2763}
2764
2765void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2766 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
2767 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002768 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002769
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002770 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002771 cb_state->transform_feedback_active = false;
2772}
2773
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002774void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
2775 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002776 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002777
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002778 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002779 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002780 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
2781 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002782}
2783
2784void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002785 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002786
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002787 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002788 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002789 cb_state->conditional_rendering_inside_render_pass = false;
2790 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002791}
2792
amhagana448ea52021-11-02 14:09:14 -04002793void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002794 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04002795 cb_state->activeRenderPass = nullptr;
2796}
2797
2798void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
2799 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002800 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04002801 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
2802}
2803
2804void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
2805 RecordCmdEndRenderingRenderPassState(commandBuffer);
2806}
2807
Tony-LunarG977448c2019-12-02 14:52:02 -07002808void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
2809 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002810 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002811 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002812 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07002813}
2814
locke-lunargd556cc32019-09-17 01:21:23 -06002815void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002816 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002817 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002818}
2819
2820void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002821 const VkSubpassBeginInfo *pSubpassBeginInfo,
2822 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002823 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002824 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002825}
2826
Tony-LunarG977448c2019-12-02 14:52:02 -07002827void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002828 const VkSubpassBeginInfo *pSubpassBeginInfo,
2829 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002830 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002831 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002832}
2833
2834void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002835 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002836 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06002837}
2838
2839void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002840 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002841 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002842 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06002843}
2844
Tony-LunarG977448c2019-12-02 14:52:02 -07002845void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002846 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002847 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002848 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07002849}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002850
locke-lunargd556cc32019-09-17 01:21:23 -06002851void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
2852 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002853 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002854
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002855 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06002856}
2857
2858void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
2859 VkFlags flags, void **ppData, VkResult result) {
2860 if (VK_SUCCESS != result) return;
2861 RecordMappedMemory(mem, offset, size, ppData);
2862}
2863
2864void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002865 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06002866 if (mem_info) {
2867 mem_info->mapped_range = MemRange();
2868 mem_info->p_driver_data = nullptr;
2869 }
2870}
2871
2872void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002873 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06002874 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06002875 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
2876 // See: VUID-vkGetImageSubresourceLayout-image-01895
2877 image_state->fragment_encoder =
2878 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002879 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002880 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002881 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06002882 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002883 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07002884
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002885 if (!swapchain_image.fake_base_address) {
2886 auto size = image_state->fragment_encoder->TotalSize();
2887 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002888 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002889 // All images bound to this swapchain and index are aliases
2890 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06002891 }
2892 } else {
2893 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06002894 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06002895 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002896 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06002897 }
locke-lunargd556cc32019-09-17 01:21:23 -06002898 }
locke-lunargd556cc32019-09-17 01:21:23 -06002899 }
2900}
2901
2902void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
2903 VkDeviceSize memoryOffset, VkResult result) {
2904 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002905 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002906 bind_info.image = image;
2907 bind_info.memory = mem;
2908 bind_info.memoryOffset = memoryOffset;
2909 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06002910}
2911
2912void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002913 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002914 if (VK_SUCCESS != result) return;
2915 for (uint32_t i = 0; i < bindInfoCount; i++) {
2916 UpdateBindImageMemoryState(pBindInfos[i]);
2917 }
2918}
2919
2920void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002921 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002922 if (VK_SUCCESS != result) return;
2923 for (uint32_t i = 0; i < bindInfoCount; i++) {
2924 UpdateBindImageMemoryState(pBindInfos[i]);
2925 }
2926}
2927
2928void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002929 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06002930 if (event_state) {
2931 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
2932 }
locke-lunargd556cc32019-09-17 01:21:23 -06002933}
2934
2935void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
2936 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
2937 VkResult result) {
2938 if (VK_SUCCESS != result) return;
2939 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
2940 pImportSemaphoreFdInfo->flags);
2941}
2942
2943void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002944 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002945 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07002946 if (semaphore_state) {
2947 semaphore_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06002948 }
2949}
2950
2951#ifdef VK_USE_PLATFORM_WIN32_KHR
2952void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
2953 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
2954 if (VK_SUCCESS != result) return;
2955 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
2956 pImportSemaphoreWin32HandleInfo->flags);
2957}
2958
2959void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
2960 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
2961 HANDLE *pHandle, VkResult result) {
2962 if (VK_SUCCESS != result) return;
2963 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
2964}
2965
2966void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
2967 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
2968 if (VK_SUCCESS != result) return;
2969 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
2970 pImportFenceWin32HandleInfo->flags);
2971}
2972
2973void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
2974 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
2975 HANDLE *pHandle, VkResult result) {
2976 if (VK_SUCCESS != result) return;
2977 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
2978}
2979#endif
2980
2981void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
2982 VkResult result) {
2983 if (VK_SUCCESS != result) return;
2984 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
2985}
2986
Mike Schuchardt2df08912020-12-15 16:28:09 -08002987void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
2988 VkFenceImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002989 auto fence_node = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07002990
2991 if (fence_node) {
2992 fence_node->Import(handle_type, flags);
locke-lunargd556cc32019-09-17 01:21:23 -06002993 }
2994}
2995
2996void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
2997 VkResult result) {
2998 if (VK_SUCCESS != result) return;
2999 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3000}
3001
Mike Schuchardt2df08912020-12-15 16:28:09 -08003002void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003003 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003004 if (fence_state) {
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003005 fence_state->Export(handle_type);
locke-lunargd556cc32019-09-17 01:21:23 -06003006 }
3007}
3008
3009void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3010 VkResult result) {
3011 if (VK_SUCCESS != result) return;
3012 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3013}
3014
3015void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3016 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3017 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003018 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003019}
3020
3021void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003022 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003023 SWAPCHAIN_NODE *old_swapchain_state) {
3024 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003025 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003026 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003027 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003028 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3029 surface_state->AddParent(swapchain.get());
3030 surface_state->swapchain = swapchain.get();
3031 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003032 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003033 } else {
3034 surface_state->swapchain = nullptr;
3035 }
3036 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003037 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003038 if (old_swapchain_state) {
3039 old_swapchain_state->retired = true;
3040 }
3041 return;
3042}
3043
3044void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3045 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3046 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003047 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003048 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003049 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003050}
3051
3052void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3053 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003054 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003055}
3056
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003057void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3058 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3059 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3060 VkResult result) {
3061 if (VK_SUCCESS != result) return;
3062 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003063 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003064}
3065
locke-lunargd556cc32019-09-17 01:21:23 -06003066void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003067 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06003068 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3069 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003070 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003071 if (semaphore_state) {
Jeremy Gebben15332642021-12-15 19:33:15 -07003072 semaphore_state->EnqueuePresent(queue_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003073 }
3074 }
3075
Tony-LunarG6f887e52021-07-27 11:23:14 -06003076 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003077 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3078 // 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
3079 // confused itself just as much.
3080 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3081 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3082 // Mark the image as having been released to the WSI
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003083 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003084 if (swapchain_data) {
3085 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003086 if (present_id_info) {
3087 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3088 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3089 }
3090 }
locke-lunargd556cc32019-09-17 01:21:23 -06003091 }
3092 }
locke-lunargd556cc32019-09-17 01:21:23 -06003093}
3094
3095void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3096 const VkSwapchainCreateInfoKHR *pCreateInfos,
3097 const VkAllocationCallbacks *pAllocator,
3098 VkSwapchainKHR *pSwapchains, VkResult result) {
3099 if (pCreateInfos) {
3100 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003101 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003102 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003103 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3104 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003105 }
3106 }
3107}
3108
3109void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3110 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003111 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003112 if (fence_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003113 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3114 // import
Jeremy Gebben140a0a52021-12-15 18:22:34 -07003115 fence_state->EnqueueSignal(nullptr, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06003116 }
3117
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003118 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben15332642021-12-15 19:33:15 -07003119 if (semaphore_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003120 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3121 // temporary import
Jeremy Gebben15332642021-12-15 19:33:15 -07003122 semaphore_state->EnqueueAcquire();
locke-lunargd556cc32019-09-17 01:21:23 -06003123 }
3124
3125 // Mark the image as acquired.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003126 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003127 if (swapchain_data) {
3128 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003129 }
3130}
3131
3132void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3133 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3134 VkResult result) {
3135 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3136 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3137}
3138
3139void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3140 uint32_t *pImageIndex, VkResult result) {
3141 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3142 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3143 pAcquireInfo->fence, pImageIndex);
3144}
3145
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003146std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3147 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3148}
3149
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003150void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3151 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3152 VkResult result) {
3153 if (result != VK_SUCCESS) {
3154 return;
3155 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003156 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003157 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003158 // this can fail if the allocator fails
3159 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3160 if (result != VK_SUCCESS) {
3161 return;
3162 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003163 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003164 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3165 if (result != VK_SUCCESS) {
3166 return;
3167 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003168
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003169 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003170 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003171 }
3172}
3173
3174// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003175static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003176 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003177}
3178
3179void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3180 uint32_t *pQueueFamilyPropertyCount,
3181 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003182 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3183 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003184 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003185}
3186
3187void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003188 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003189 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3190 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003191 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003192}
3193
3194void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003195 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003196 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3197 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003198 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003199}
3200void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3201 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003202 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003203}
3204
Jeremy Gebben082a9832021-10-28 13:40:11 -06003205void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003206
3207void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3208 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3209 const VkAllocationCallbacks *pAllocator,
3210 VkSurfaceKHR *pSurface, VkResult result) {
3211 if (VK_SUCCESS != result) return;
3212 RecordVulkanSurface(pSurface);
3213}
3214
3215#ifdef VK_USE_PLATFORM_ANDROID_KHR
3216void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3217 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3218 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3219 VkResult result) {
3220 if (VK_SUCCESS != result) return;
3221 RecordVulkanSurface(pSurface);
3222}
3223#endif // VK_USE_PLATFORM_ANDROID_KHR
3224
3225#ifdef VK_USE_PLATFORM_IOS_MVK
3226void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3227 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3228 VkResult result) {
3229 if (VK_SUCCESS != result) return;
3230 RecordVulkanSurface(pSurface);
3231}
3232#endif // VK_USE_PLATFORM_IOS_MVK
3233
3234#ifdef VK_USE_PLATFORM_MACOS_MVK
3235void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3236 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3237 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3238 VkResult result) {
3239 if (VK_SUCCESS != result) return;
3240 RecordVulkanSurface(pSurface);
3241}
3242#endif // VK_USE_PLATFORM_MACOS_MVK
3243
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003244#ifdef VK_USE_PLATFORM_METAL_EXT
3245void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3246 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3247 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3248 VkResult result) {
3249 if (VK_SUCCESS != result) return;
3250 RecordVulkanSurface(pSurface);
3251}
3252#endif // VK_USE_PLATFORM_METAL_EXT
3253
locke-lunargd556cc32019-09-17 01:21:23 -06003254#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3255void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3256 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3257 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3258 VkResult result) {
3259 if (VK_SUCCESS != result) return;
3260 RecordVulkanSurface(pSurface);
3261}
3262#endif // VK_USE_PLATFORM_WAYLAND_KHR
3263
3264#ifdef VK_USE_PLATFORM_WIN32_KHR
3265void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3266 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3267 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3268 VkResult result) {
3269 if (VK_SUCCESS != result) return;
3270 RecordVulkanSurface(pSurface);
3271}
3272#endif // VK_USE_PLATFORM_WIN32_KHR
3273
3274#ifdef VK_USE_PLATFORM_XCB_KHR
3275void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3276 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3277 VkResult result) {
3278 if (VK_SUCCESS != result) return;
3279 RecordVulkanSurface(pSurface);
3280}
3281#endif // VK_USE_PLATFORM_XCB_KHR
3282
3283#ifdef VK_USE_PLATFORM_XLIB_KHR
3284void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3285 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3286 VkResult result) {
3287 if (VK_SUCCESS != result) return;
3288 RecordVulkanSurface(pSurface);
3289}
3290#endif // VK_USE_PLATFORM_XLIB_KHR
3291
Niklas Haas8b84af12020-04-19 22:20:11 +02003292void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3293 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3294 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3295 VkResult result) {
3296 if (VK_SUCCESS != result) return;
3297 RecordVulkanSurface(pSurface);
3298}
3299
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003300void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3301 VkSurfaceKHR surface,
3302 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3303 VkResult result) {
3304 if (VK_SUCCESS != result) return;
3305 auto surface_state = Get<SURFACE_STATE>(surface);
3306 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3307}
3308
3309void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3310 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3311 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3312 if (VK_SUCCESS != result) return;
3313 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3314 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3315}
3316
3317void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3318 VkSurfaceKHR surface,
3319 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3320 VkResult result) {
3321 auto surface_state = Get<SURFACE_STATE>(surface);
3322 VkSurfaceCapabilitiesKHR caps{
3323 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3324 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3325 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3326 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3327 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3328 };
3329 surface_state->SetCapabilities(physicalDevice, caps);
3330}
3331
locke-lunargd556cc32019-09-17 01:21:23 -06003332void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3333 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3334 VkBool32 *pSupported, VkResult result) {
3335 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003336 auto surface_state = Get<SURFACE_STATE>(surface);
3337 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3338}
3339
3340void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3341 VkSurfaceKHR surface,
3342 uint32_t *pPresentModeCount,
3343 VkPresentModeKHR *pPresentModes,
3344 VkResult result) {
3345 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3346
3347 if (pPresentModes) {
3348 auto surface_state = Get<SURFACE_STATE>(surface);
3349 surface_state->SetPresentModes(physicalDevice,
3350 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3351 }
3352}
3353
3354void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3355 uint32_t *pSurfaceFormatCount,
3356 VkSurfaceFormatKHR *pSurfaceFormats,
3357 VkResult result) {
3358 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3359
3360 if (pSurfaceFormats) {
3361 auto surface_state = Get<SURFACE_STATE>(surface);
3362 surface_state->SetFormats(physicalDevice,
3363 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3364 }
3365}
3366
3367void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3368 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3369 uint32_t *pSurfaceFormatCount,
3370 VkSurfaceFormat2KHR *pSurfaceFormats,
3371 VkResult result) {
3372 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3373
3374 if (pSurfaceFormats) {
3375 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3376 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3377 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3378 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3379 }
3380 surface_state->SetFormats(physicalDevice, std::move(fmts));
3381 }
locke-lunargd556cc32019-09-17 01:21:23 -06003382}
3383
locke-lunargd556cc32019-09-17 01:21:23 -06003384void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3385 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003386 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003387 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003388 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3389}
3390
3391void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003392 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003393 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003394 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3395}
3396
3397void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3398 const VkDebugUtilsLabelEXT *pLabelInfo) {
3399 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3400
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003401 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003402 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3403 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003404 cb_state->debug_label = LoggingLabel(pLabelInfo);
3405}
3406
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003407void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3408 uint32_t queueFamilyIndex,
3409 uint32_t *pCounterCount,
3410 VkPerformanceCounterKHR *pCounters) {
3411 if (NULL == pCounters) return;
3412
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003413 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3414 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003415
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003416 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3417 queue_family_counters->counters.resize(*pCounterCount);
3418 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003419
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003420 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003421}
3422
3423void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3424 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3425 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3426 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3427 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3428}
3429
3430void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3431 VkResult result) {
3432 if (result == VK_SUCCESS) performance_lock_acquired = true;
3433}
3434
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003435void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3436 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003437 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003438 cmd_buffer.second->performance_lock_released = true;
3439 }
3440}
3441
locke-lunargd556cc32019-09-17 01:21:23 -06003442void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003443 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003444 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003445 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003446}
3447
3448void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003449 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003450 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003451 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003452}
3453
Mike Schuchardt2df08912020-12-15 16:28:09 -08003454void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3455 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003456 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003457}
3458
Mike Schuchardt2df08912020-12-15 16:28:09 -08003459void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3460 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3461 const VkAllocationCallbacks *pAllocator,
3462 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3463 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003464 if (VK_SUCCESS != result) return;
3465 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3466}
3467
3468void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003469 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3470 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003471 if (VK_SUCCESS != result) return;
3472 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3473}
3474
3475void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003476 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003477 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003478 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3479 assert(template_state);
3480 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003481 // TODO: Record template push descriptor updates
3482 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003483 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003484 }
3485 }
3486}
3487
3488void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3489 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3490 const void *pData) {
3491 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3492}
3493
3494void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003495 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003496 const void *pData) {
3497 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3498}
3499
Mike Schuchardt2df08912020-12-15 16:28:09 -08003500void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3501 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3502 VkPipelineLayout layout, uint32_t set,
3503 const void *pData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003504 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003505
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003506 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003507 const auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003508 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003509 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003510 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003511 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003512 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003513 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003514 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003515 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003516 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3517 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003518 }
3519}
3520
3521void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3522 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003523 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003524 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003525 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003526 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003527 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003528 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003529 }
3530}
3531
3532void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3533 uint32_t *pPropertyCount,
3534 VkDisplayPlanePropertiesKHR *pProperties,
3535 VkResult result) {
3536 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3537 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3538}
3539
3540void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3541 uint32_t *pPropertyCount,
3542 VkDisplayPlaneProperties2KHR *pProperties,
3543 VkResult result) {
3544 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3545 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3546}
3547
3548void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3549 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3550 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003551 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003552 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003553 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003554}
3555
3556void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3557 uint32_t query, uint32_t index) {
3558 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003559 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003560 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003561 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003562}
3563
3564void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3565 VkSamplerYcbcrConversion ycbcr_conversion) {
Lionel Landwerlin21719f62021-12-09 11:40:09 +02003566 VkFormatFeatureFlags2KHR format_features = 0;
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003567
3568 if (create_info->format != VK_FORMAT_UNDEFINED) {
3569 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003570 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003571 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3572 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003573 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003574
Jeremy Gebben082a9832021-10-28 13:40:11 -06003575 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003576}
3577
3578void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3579 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3580 const VkAllocationCallbacks *pAllocator,
3581 VkSamplerYcbcrConversion *pYcbcrConversion,
3582 VkResult result) {
3583 if (VK_SUCCESS != result) return;
3584 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3585}
3586
3587void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3588 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3589 const VkAllocationCallbacks *pAllocator,
3590 VkSamplerYcbcrConversion *pYcbcrConversion,
3591 VkResult result) {
3592 if (VK_SUCCESS != result) return;
3593 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3594}
3595
3596void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3597 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003598 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003599}
3600
3601void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3602 VkSamplerYcbcrConversion ycbcrConversion,
3603 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003604 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003605}
3606
Tony-LunarG977448c2019-12-02 14:52:02 -07003607void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3608 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003609 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003610 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003611
3612 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003613 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003614 if (!query_pool_state) return;
3615
3616 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003617 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3618 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003619 auto query_index = firstQuery + i;
3620 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003621 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003622 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003623 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003624 }
3625 }
locke-lunargd556cc32019-09-17 01:21:23 -06003626 }
3627}
3628
Tony-LunarG977448c2019-12-02 14:52:02 -07003629void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3630 uint32_t queryCount) {
3631 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3632}
3633
3634void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3635 uint32_t queryCount) {
3636 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3637}
3638
locke-lunargd556cc32019-09-17 01:21:23 -06003639void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003640 const UPDATE_TEMPLATE_STATE *template_state,
3641 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003642 // Translate the templated update into a normal update for validation...
3643 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3644 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3645 decoded_update.desc_writes.data(), 0, NULL);
3646}
3647
3648// Update the common AllocateDescriptorSetsData
3649void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003650 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003651 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003652 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003653 if (layout) {
3654 ds_data->layout_nodes[i] = layout;
3655 // Count total descriptors required per type
3656 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3657 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003658 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3659 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003660 }
3661 }
3662 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3663 }
3664}
3665
locke-lunargd556cc32019-09-17 01:21:23 -06003666void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3667 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003668 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003669 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003670}
3671
Tony-LunarG745150c2021-07-02 15:07:31 -06003672void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3673 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3674 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003675 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003676 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003677}
3678
locke-lunargd556cc32019-09-17 01:21:23 -06003679void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
3680 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
3681 uint32_t firstInstance) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003682 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003683 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003684}
3685
Tony-LunarG745150c2021-07-02 15:07:31 -06003686void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3687 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
3688 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
3689 const int32_t *pVertexOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003690 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003691 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003692}
3693
locke-lunargd556cc32019-09-17 01:21:23 -06003694void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3695 uint32_t count, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003696 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3697 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003698 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003699 if (!disabled[command_buffer_state]) {
3700 cb_state->AddChild(buffer_state);
3701 }
locke-lunargd556cc32019-09-17 01:21:23 -06003702}
3703
3704void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3705 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003706 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3707 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003708 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003709 if (!disabled[command_buffer_state]) {
3710 cb_state->AddChild(buffer_state);
3711 }
locke-lunargd556cc32019-09-17 01:21:23 -06003712}
3713
3714void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003715 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003716 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06003717}
3718
3719void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3720 VkDeviceSize offset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003721 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003722 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003723 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003724 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003725 cb_state->AddChild(buffer_state);
3726 }
locke-lunargd556cc32019-09-17 01:21:23 -06003727}
3728
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003729void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3730 uint32_t, uint32_t) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003731 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003732 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3733}
3734
3735void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3736 uint32_t, uint32_t) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003737 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003738 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3739}
3740
Tony-LunarG977448c2019-12-02 14:52:02 -07003741void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3742 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07003743 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003744 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003745 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003746 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003747 auto buffer_state = Get<BUFFER_STATE>(buffer);
3748 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003749 cb_state->AddChild(buffer_state);
3750 cb_state->AddChild(count_buffer_state);
3751 }
Tony-LunarG977448c2019-12-02 14:52:02 -07003752}
3753
locke-lunargd556cc32019-09-17 01:21:23 -06003754void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3755 VkDeviceSize offset, VkBuffer countBuffer,
3756 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3757 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003758 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003759 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003760}
3761
3762void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3763 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
3764 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003765 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003766 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07003767}
3768
3769void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3770 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07003771 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003772 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003773 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003774 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003775 auto buffer_state = Get<BUFFER_STATE>(buffer);
3776 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003777 cb_state->AddChild(buffer_state);
3778 cb_state->AddChild(count_buffer_state);
3779 }
locke-lunargd556cc32019-09-17 01:21:23 -06003780}
3781
3782void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3783 VkDeviceSize offset, VkBuffer countBuffer,
3784 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3785 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003786 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003787 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003788}
3789
3790void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
3791 VkDeviceSize offset, VkBuffer countBuffer,
3792 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3793 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003794 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003795 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06003796}
3797
3798void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
3799 uint32_t firstTask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003800 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003801 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003802}
3803
3804void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
3805 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003806 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003807 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003808 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003809 if (!disabled[command_buffer_state] && buffer_state) {
3810 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003811 }
3812}
3813
3814void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
3815 VkDeviceSize offset, VkBuffer countBuffer,
3816 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3817 uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003818 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003819 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003820 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003821 auto buffer_state = Get<BUFFER_STATE>(buffer);
3822 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003823 if (buffer_state) {
3824 cb_state->AddChild(buffer_state);
3825 }
3826 if (count_buffer_state) {
3827 cb_state->AddChild(count_buffer_state);
3828 }
locke-lunargd556cc32019-09-17 01:21:23 -06003829 }
3830}
3831
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003832void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
3833 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
3834 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
3835 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
3836 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
3837 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
3838 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003839 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003840 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003841 cb_state->hasTraceRaysCmd = true;
3842}
3843
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003844void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
3845 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
3846 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
3847 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
3848 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
3849 uint32_t height, uint32_t depth) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003850 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003851 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003852 cb_state->hasTraceRaysCmd = true;
3853}
3854
3855void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
3856 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
3857 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
3858 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
3859 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
3860 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003861 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003862 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003863 cb_state->hasTraceRaysCmd = true;
3864}
3865
locke-lunargd556cc32019-09-17 01:21:23 -06003866void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
3867 const VkAllocationCallbacks *pAllocator,
3868 VkShaderModule *pShaderModule, VkResult result,
3869 void *csm_state_data) {
3870 if (VK_SUCCESS != result) return;
3871 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
3872
sfricke-samsung45996a42021-09-16 13:45:27 -07003873 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06003874 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003875 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
3876 csm_state->unique_shader_id)
3877 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06003878 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06003879}
3880
John Zulauf22b0fbe2019-10-15 06:26:16 -06003881void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
3882 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
3883 VkResult result) {
3884 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06003885 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06003886
3887 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
3888
3889 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06003890 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07003891 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07003892 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06003893
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003894 auto format_features =
3895 GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format,
3896 swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06003897
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06003898 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003899 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003900 if (!swapchain_image.fake_base_address) {
3901 auto size = image_state->fragment_encoder->TotalSize();
3902 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07003903 }
3904
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003905 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003906 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06003907 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06003908 }
3909 }
3910
3911 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06003912 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
3913 }
3914}
sourav parmar35e7a002020-06-09 17:58:44 -07003915
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02003916void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
3917 const VkCopyAccelerationStructureInfoKHR *pInfo,
3918 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003919 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
3920 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02003921 if (dst_as_state != nullptr && src_as_state != nullptr) {
3922 dst_as_state->built = true;
3923 dst_as_state->build_info_khr = src_as_state->build_info_khr;
3924 }
3925}
3926
sourav parmar35e7a002020-06-09 17:58:44 -07003927void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
3928 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003929 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07003930 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003931 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003932 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
3933 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07003934 if (dst_as_state != nullptr && src_as_state != nullptr) {
3935 dst_as_state->built = true;
3936 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003937 if (!disabled[command_buffer_state]) {
3938 cb_state->AddChild(dst_as_state);
3939 cb_state->AddChild(src_as_state);
3940 }
sourav parmar35e7a002020-06-09 17:58:44 -07003941 }
3942 }
3943}
Piers Daniell39842ee2020-07-10 16:42:33 -06003944
3945void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003946 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003947 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003948}
3949
3950void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003951 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003952 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003953}
3954
3955void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
3956 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003957 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003958 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003959 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06003960}
3961
3962void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
3963 const VkViewport *pViewports) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003964 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003965 cb_state->RecordStateCmd(CMD_SETVIEWPORTWITHCOUNTEXT, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07003966 uint32_t bits = (1u << viewportCount) - 1u;
3967 cb_state->viewportWithCountMask |= bits;
3968 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00003969 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07003970 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07003971
3972 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
3973 for (size_t i = 0; i < viewportCount; ++i) {
3974 cb_state->dynamicViewports[i] = pViewports[i];
3975 }
Piers Daniell39842ee2020-07-10 16:42:33 -06003976}
3977
3978void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
3979 const VkRect2D *pScissors) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003980 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003981 cb_state->RecordStateCmd(CMD_SETSCISSORWITHCOUNTEXT, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07003982 uint32_t bits = (1u << scissorCount) - 1u;
3983 cb_state->scissorWithCountMask |= bits;
3984 cb_state->trashedScissorMask &= ~bits;
3985 cb_state->scissorWithCountCount = scissorCount;
3986 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06003987}
3988
3989void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
3990 uint32_t bindingCount, const VkBuffer *pBuffers,
3991 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
3992 const VkDeviceSize *pStrides) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003993 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003994 cb_state->RecordStateCmd(CMD_BINDVERTEXBUFFERS2EXT, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06003995
3996 uint32_t end = firstBinding + bindingCount;
3997 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
3998 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
3999 }
4000
4001 for (uint32_t i = 0; i < bindingCount; ++i) {
4002 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004003 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004004 vertex_buffer_binding.offset = pOffsets[i];
4005 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4006 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4007 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004008 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004009 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004010 }
4011 }
4012}
4013
4014void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004015 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004016 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004017}
4018
4019void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004020 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004021 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004022}
4023
4024void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004025 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004026 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004027}
4028
4029void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4030 VkBool32 depthBoundsTestEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004031 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004032 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004033}
4034void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004035 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004036 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004037}
4038
4039void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4040 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4041 VkCompareOp compareOp) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004042 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004043 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004044}
locke-lunarg4189aa22020-10-21 00:23:48 -06004045
4046void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4047 uint32_t discardRectangleCount,
4048 const VkRect2D *pDiscardRectangles) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004049 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004050 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004051}
4052
4053void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4054 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004055 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004056 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004057}
4058
4059void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4060 VkCoarseSampleOrderTypeNV sampleOrderType,
4061 uint32_t customSampleOrderCount,
4062 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004063 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004064 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004065}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004066
4067void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004068 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004069 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004070}
4071
4072void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004073 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004074 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004075}
4076
4077void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4078 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004079 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004080 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004081}
4082
4083void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004084 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004085 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004086}
4087
4088void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4089 VkBool32 primitiveRestartEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004090 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004091 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004092}
Piers Daniell924cd832021-05-18 13:48:47 -06004093
4094void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4095 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4096 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4097 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004098 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004099 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4100
4101 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4102 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4103 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004104 if (pipeline_state->create_info.graphics.pDynamicState) {
4105 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4106 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004107 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4108 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4109 break;
4110 }
4111 }
4112 }
4113 }
4114 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004115}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004116
4117void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004118 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004119 if (buffer_state) {
4120 // address is used for GPU-AV and ray tracing buffer validation
4121 buffer_state->deviceAddress = address;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06004122 buffer_address_map_.insert(address, buffer_state.get());
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004123 }
4124}
4125
4126void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4127 VkDeviceAddress address) {
4128 RecordGetBufferDeviceAddress(pInfo, address);
4129}
4130
4131void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4132 VkDeviceAddress address) {
4133 RecordGetBufferDeviceAddress(pInfo, address);
4134}
4135
4136void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4137 VkDeviceAddress address) {
4138 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004139}
4140
4141std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4142 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004143 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004144}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004145
4146std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4147 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004148 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004149 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4150}