blob: 75aedacf625988794d9886a7cbd79cfd5335ffaa [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>
99VkFormatFeatureFlags ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
100 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;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700115 auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700116 if (ahb_format_props) {
Jeremy Gebben65975ed2021-10-29 11:16:10 -0600117 ahb_ext_formats_map.insert(ahb_format_props->externalFormat, ahb_format_props->formatFeatures);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700118 }
119}
120
locke-lunargd556cc32019-09-17 01:21:23 -0600121#else
122
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -0600123template <typename CreateInfo>
124VkFormatFeatureFlags ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
125 return 0;
126}
locke-lunargd556cc32019-09-17 01:21:23 -0600127
128#endif // VK_USE_PLATFORM_ANDROID_KHR
129
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600130VkFormatFeatureFlags GetImageFormatFeatures(VkPhysicalDevice physical_device, VkDevice device, VkImage image, VkFormat format,
131 VkImageTiling tiling) {
132 VkFormatFeatureFlags format_features = 0;
Petr Kraus44f1c482020-04-25 20:09:25 +0200133 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
134 // if format is AHB external format then the features are already set
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600135 if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
136 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
137 nullptr};
138 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
Petr Kraus44f1c482020-04-25 20:09:25 +0200139
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600140 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
141 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
142 nullptr};
143 format_properties_2.pNext = (void *)&drm_properties_list;
144 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
145 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
146 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
147 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
148 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200149
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600150 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
151 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
152 format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
153 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200154 }
Petr Kraus44f1c482020-04-25 20:09:25 +0200155 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600156 } else {
157 VkFormatProperties format_properties;
158 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
159 format_features =
160 (tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
Petr Kraus44f1c482020-04-25 20:09:25 +0200161 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600162 return format_features;
Petr Kraus44f1c482020-04-25 20:09:25 +0200163}
164
locke-lunargd556cc32019-09-17 01:21:23 -0600165void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
166 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
167 if (VK_SUCCESS != result) return;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600168 VkFormatFeatureFlags format_features = 0;
sfricke-samsung45996a42021-09-16 13:45:27 -0700169 if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600170 format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600171 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600172 if (format_features == 0) {
173 format_features = GetImageFormatFeatures(physical_device, device, *pImage, pCreateInfo->format, pCreateInfo->tiling);
locke-lunargd556cc32019-09-17 01:21:23 -0600174 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600175 Add(std::make_shared<IMAGE_STATE>(this, *pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600176}
177
178void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600179 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600180}
181
182void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
183 VkImageLayout imageLayout, const VkClearColorValue *pColor,
184 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600185 if (disabled[command_buffer_state]) return;
186
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600187 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600188 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600189 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600190 }
191}
192
193void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
194 VkImageLayout imageLayout,
195 const VkClearDepthStencilValue *pDepthStencil,
196 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600197 if (disabled[command_buffer_state]) return;
198
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600199 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600200 if (cb_node) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600201 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600202 }
203}
204
205void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
206 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
207 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600208 if (disabled[command_buffer_state]) return;
209
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600210 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600211 cb_node->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600212}
213
Jeff Leger178b1e52020-10-05 12:22:23 -0400214void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
215 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600216 if (disabled[command_buffer_state]) return;
217
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600218 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600219 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
220 Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400221}
222
locke-lunargd556cc32019-09-17 01:21:23 -0600223void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
224 VkImageLayout srcImageLayout, VkImage dstImage,
225 VkImageLayout dstImageLayout, uint32_t regionCount,
226 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600227 if (disabled[command_buffer_state]) return;
228
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600229 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600230 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600231}
232
Jeff Leger178b1e52020-10-05 12:22:23 -0400233void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
234 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600235 if (disabled[command_buffer_state]) return;
236
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600237 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600238 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
239 Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400240}
241
locke-lunargd556cc32019-09-17 01:21:23 -0600242void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
243 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
244 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600245 if (disabled[command_buffer_state]) return;
246
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600247 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600248 cb_node->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600249}
250
Jeff Leger178b1e52020-10-05 12:22:23 -0400251void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
252 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600253 if (disabled[command_buffer_state]) return;
254
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600255 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600256 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
257 Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400258}
259
locke-lunargd556cc32019-09-17 01:21:23 -0600260void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
261 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
262 VkResult result) {
263 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600264
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600265 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600266
James Rumble2f6e7bb2021-07-13 15:21:20 +0100267 if (pCreateInfo) {
268 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
269 if (opaque_capture_address) {
270 // address is used for GPU-AV and ray tracing buffer validation
271 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
Jeremy Gebben65975ed2021-10-29 11:16:10 -0600272 buffer_address_map_.insert(opaque_capture_address->opaqueCaptureAddress, buffer_state.get());
James Rumble2f6e7bb2021-07-13 15:21:20 +0100273 }
274 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600275 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600276}
277
278void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
279 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
280 VkResult result) {
281 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600282
Jeremy Gebben9f537102021-10-05 16:37:12 -0600283 auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600284
285 VkFormatProperties format_properties;
286 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
locke-lunarg25b6c352020-08-06 17:44:18 -0600287
Jeremy Gebben082a9832021-10-28 13:40:11 -0600288 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, format_properties.bufferFeatures));
locke-lunargd556cc32019-09-17 01:21:23 -0600289}
290
291void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
292 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
293 VkResult result) {
294 if (result != VK_SUCCESS) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -0600295 auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700296
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600297 VkFormatFeatureFlags format_features = 0;
298 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700299 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600300 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700301 } else {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600302 format_features = GetImageFormatFeatures(physical_device, device, image_state->image(), pCreateInfo->format,
303 image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700304 }
305
locke-lunarg9939d4b2020-10-26 20:11:08 -0600306 // 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 -0600307 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600308 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700309 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600310 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700311 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600312 image_format_info.type = image_state->createInfo.imageType;
313 image_format_info.format = image_state->createInfo.format;
314 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600315 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
316 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600317 image_format_info.flags = image_state->createInfo.flags;
318
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600319 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600320
321 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
322 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600323
Jeremy Gebben082a9832021-10-28 13:40:11 -0600324 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600325}
326
327void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
328 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600329 if (disabled[command_buffer_state]) return;
330
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600331 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600332 cb_node->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600333}
334
Jeff Leger178b1e52020-10-05 12:22:23 -0400335void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600336 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600337 if (disabled[command_buffer_state]) return;
338
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600339 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600340 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
341 Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400342}
343
locke-lunargd556cc32019-09-17 01:21:23 -0600344void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
345 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600346 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600347}
348
349void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600350 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600351}
352
353void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
354 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600355 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600356}
357
358void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
359 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600360 if (disabled[command_buffer_state]) return;
361
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600362 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600363 cb_node->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600364}
365
366void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
367 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
368 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600369 if (disabled[command_buffer_state]) return;
370
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600371 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600372
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600373 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600374}
375
Jeff Leger178b1e52020-10-05 12:22:23 -0400376void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
377 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600378 if (disabled[command_buffer_state]) return;
379
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600380 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600381 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
382 Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400383}
384
locke-lunargd556cc32019-09-17 01:21:23 -0600385void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
386 VkImageLayout dstImageLayout, uint32_t regionCount,
387 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600388 if (disabled[command_buffer_state]) return;
389
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600390 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600391 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600392}
393
Jeff Leger178b1e52020-10-05 12:22:23 -0400394void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
395 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600396 if (disabled[command_buffer_state]) return;
397
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600398 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600399 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
400 Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400401}
402
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700403// Gets union of all features defined by Potential Format Features
404// except, does not handle the external format case for AHB as that only can be used for sampled images
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700405VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
406 VkFormatFeatureFlags format_features = 0;
407
408 if (format != VK_FORMAT_UNDEFINED) {
409 VkFormatProperties format_properties;
410 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
411 format_features |= format_properties.linearTilingFeatures;
412 format_features |= format_properties.optimalTilingFeatures;
sfricke-samsung45996a42021-09-16 13:45:27 -0700413 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700414 // VK_KHR_get_physical_device_properties2 is required in this case
415 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
416 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
417 nullptr};
418 format_properties_2.pNext = (void *)&drm_properties_list;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100419
420 // First call is to get the number of modifiers compatible with the queried format
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700421 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100422
423 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
424 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
425 drm_properties_list.pDrmFormatModifierProperties = drm_properties.data();
426
427 // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers
428 // compatible with the queried format
429 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
430
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700431 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
432 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
433 }
434 }
435 }
436
437 return format_features;
438}
439
locke-lunargd556cc32019-09-17 01:21:23 -0600440void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
441 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
442 VkResult result) {
443 if (VK_SUCCESS != result) return;
444
Locke Linf3873542021-04-26 11:25:10 -0600445 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
446 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
447 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
448
locke-lunargd556cc32019-09-17 01:21:23 -0600449 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
450 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700451 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600452 if (features2) {
453 enabled_features_found = &(features2->features);
454 }
455 }
456
locke-lunargd556cc32019-09-17 01:21:23 -0600457 if (nullptr == enabled_features_found) {
458 state_tracker->enabled_features.core = {};
459 } else {
460 state_tracker->enabled_features.core = *enabled_features_found;
461 }
462
locke-lunargd556cc32019-09-17 01:21:23 -0600463 // Save local link to this device's physical device state
Jeremy Gebben9f537102021-10-05 16:37:12 -0600464 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
locke-lunargd556cc32019-09-17 01:21:23 -0600465
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700466 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700467 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700468 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700469 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700470 // Set Extension Feature Aliases to false as there is no struct to check
471 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
472 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
473 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
474 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
475 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
476 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800477 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700478
479 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700480
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700481 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700482 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700483 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
484 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
485 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
486 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700487 }
488
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700489 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700490 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700491 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
492 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700493 }
494
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700495 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700496 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700497 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
498 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
499 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
500 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
501 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
502 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
503 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
504 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
505 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
506 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
507 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
508 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
509 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
510 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
511 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
512 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
513 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
514 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
515 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
516 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
517 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
518 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
519 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
520 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
521 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
522 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
523 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
524 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
525 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
526 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
527 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
528 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
529 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
530 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
531 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
532 descriptor_indexing_features->descriptorBindingPartiallyBound;
533 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
534 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
535 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700536 }
537
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700538 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700539 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700540 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700541 }
542
543 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700544 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700545 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700546 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700547 }
548
549 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700550 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700551 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700552 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
553 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700554 }
555
556 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700557 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700558 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700559 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
560 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700561 }
562
563 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700564 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700565 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700566 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
567 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700568 }
569
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700570 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700571 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700572 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700573 }
574
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700575 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700576 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700577 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700578 }
579
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700580 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700581 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700582 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
583 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
584 buffer_device_address->bufferDeviceAddressCaptureReplay;
585 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
586 buffer_device_address->bufferDeviceAddressMultiDevice;
587 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800588
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700589 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800590 if (atomic_int64_features) {
591 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
592 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
593 }
594
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700595 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800596 if (memory_model_features) {
597 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
598 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
599 memory_model_features->vulkanMemoryModelDeviceScope;
600 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
601 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
602 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700603 }
604
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700605 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700606 if (vulkan_11_features) {
607 state_tracker->enabled_features.core11 = *vulkan_11_features;
608 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700609 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700610
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700611 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700612 if (sixteen_bit_storage_features) {
613 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
614 sixteen_bit_storage_features->storageBuffer16BitAccess;
615 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
616 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
617 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
618 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
619 }
620
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700621 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700622 if (multiview_features) {
623 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
624 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
625 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
626 }
627
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700628 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700629 if (variable_pointers_features) {
630 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
631 variable_pointers_features->variablePointersStorageBuffer;
632 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
633 }
634
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700635 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700636 if (protected_memory_features) {
637 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
638 }
639
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700640 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700641 if (ycbcr_conversion_features) {
642 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
643 }
644
645 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700646 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700647 if (shader_draw_parameters_features) {
648 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700649 }
650 }
651
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700652 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600653 if (device_group_ci) {
654 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
655 state_tracker->device_group_create_info = *device_group_ci;
656 } else {
657 state_tracker->physical_device_count = 1;
658 }
locke-lunargd556cc32019-09-17 01:21:23 -0600659
sfricke-samsung828e59d2021-08-22 23:20:49 -0700660 // Features from other extensions passesd in create info
661 {
662 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
663 if (exclusive_scissor_features) {
664 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
665 }
locke-lunargd556cc32019-09-17 01:21:23 -0600666
sfricke-samsung828e59d2021-08-22 23:20:49 -0700667 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
668 if (shading_rate_image_features) {
669 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
670 }
locke-lunargd556cc32019-09-17 01:21:23 -0600671
sfricke-samsung828e59d2021-08-22 23:20:49 -0700672 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
673 if (mesh_shader_features) {
674 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
675 }
locke-lunargd556cc32019-09-17 01:21:23 -0600676
sfricke-samsung828e59d2021-08-22 23:20:49 -0700677 const auto *inline_uniform_block_features =
678 LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
679 if (inline_uniform_block_features) {
680 state_tracker->enabled_features.inline_uniform_block_features = *inline_uniform_block_features;
681 }
locke-lunargd556cc32019-09-17 01:21:23 -0600682
sfricke-samsung828e59d2021-08-22 23:20:49 -0700683 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
684 if (transform_feedback_features) {
685 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
686 }
locke-lunargd556cc32019-09-17 01:21:23 -0600687
sfricke-samsung828e59d2021-08-22 23:20:49 -0700688 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
689 if (vtx_attrib_div_features) {
690 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
691 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700692
sfricke-samsung828e59d2021-08-22 23:20:49 -0700693 const auto *buffer_device_address_ext_features =
694 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
695 if (buffer_device_address_ext_features) {
696 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
697 }
locke-lunargd556cc32019-09-17 01:21:23 -0600698
sfricke-samsung828e59d2021-08-22 23:20:49 -0700699 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
700 if (cooperative_matrix_features) {
701 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
702 }
locke-lunargd556cc32019-09-17 01:21:23 -0600703
sfricke-samsung828e59d2021-08-22 23:20:49 -0700704 const auto *compute_shader_derivatives_features =
705 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
706 if (compute_shader_derivatives_features) {
707 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
708 }
locke-lunargd556cc32019-09-17 01:21:23 -0600709
sfricke-samsung828e59d2021-08-22 23:20:49 -0700710 const auto *fragment_shader_barycentric_features =
711 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
712 if (fragment_shader_barycentric_features) {
713 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
714 }
locke-lunargd556cc32019-09-17 01:21:23 -0600715
sfricke-samsung828e59d2021-08-22 23:20:49 -0700716 const auto *shader_image_footprint_features =
717 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
718 if (shader_image_footprint_features) {
719 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
720 }
locke-lunargd556cc32019-09-17 01:21:23 -0600721
sfricke-samsung828e59d2021-08-22 23:20:49 -0700722 const auto *fragment_shader_interlock_features =
723 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
724 if (fragment_shader_interlock_features) {
725 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
726 }
locke-lunargd556cc32019-09-17 01:21:23 -0600727
sfricke-samsung828e59d2021-08-22 23:20:49 -0700728 const auto *demote_to_helper_invocation_features =
729 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
730 if (demote_to_helper_invocation_features) {
731 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
732 }
locke-lunargd556cc32019-09-17 01:21:23 -0600733
sfricke-samsung828e59d2021-08-22 23:20:49 -0700734 const auto *texel_buffer_alignment_features =
735 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
736 if (texel_buffer_alignment_features) {
737 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
738 }
locke-lunargd556cc32019-09-17 01:21:23 -0600739
sfricke-samsung828e59d2021-08-22 23:20:49 -0700740 const auto *pipeline_exe_props_features =
741 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
742 if (pipeline_exe_props_features) {
743 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
744 }
locke-lunargd556cc32019-09-17 01:21:23 -0600745
sfricke-samsung828e59d2021-08-22 23:20:49 -0700746 const auto *dedicated_allocation_image_aliasing_features =
747 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
748 if (dedicated_allocation_image_aliasing_features) {
749 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
750 *dedicated_allocation_image_aliasing_features;
751 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500752
sfricke-samsung828e59d2021-08-22 23:20:49 -0700753 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
754 if (performance_query_features) {
755 state_tracker->enabled_features.performance_query_features = *performance_query_features;
756 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100757
sfricke-samsung828e59d2021-08-22 23:20:49 -0700758 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
759 if (device_coherent_memory_features) {
760 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
761 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000762
sfricke-samsung828e59d2021-08-22 23:20:49 -0700763 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
764 if (ycbcr_image_array_features) {
765 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
766 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800767
sfricke-samsung828e59d2021-08-22 23:20:49 -0700768 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
769 if (ray_query_features) {
770 state_tracker->enabled_features.ray_query_features = *ray_query_features;
771 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700772
sfricke-samsung828e59d2021-08-22 23:20:49 -0700773 const auto *ray_tracing_pipeline_features =
774 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
775 if (ray_tracing_pipeline_features) {
776 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
777 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700778
sfricke-samsung828e59d2021-08-22 23:20:49 -0700779 const auto *ray_tracing_acceleration_structure_features =
780 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
781 if (ray_tracing_acceleration_structure_features) {
782 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
783 *ray_tracing_acceleration_structure_features;
784 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500785
sfricke-samsung828e59d2021-08-22 23:20:49 -0700786 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
787 if (robustness2_features) {
788 state_tracker->enabled_features.robustness2_features = *robustness2_features;
789 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500790
sfricke-samsung828e59d2021-08-22 23:20:49 -0700791 const auto *fragment_density_map_features =
792 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
793 if (fragment_density_map_features) {
794 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
795 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200796
sfricke-samsung828e59d2021-08-22 23:20:49 -0700797 const auto *fragment_density_map_features2 =
798 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
799 if (fragment_density_map_features2) {
800 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
801 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200802
sfricke-samsung828e59d2021-08-22 23:20:49 -0700803 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
804 if (astc_decode_features) {
805 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
806 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -0700807
sfricke-samsung828e59d2021-08-22 23:20:49 -0700808 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
809 if (custom_border_color_features) {
810 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
811 }
Tony-LunarG7337b312020-04-15 16:40:25 -0600812
sfricke-samsung828e59d2021-08-22 23:20:49 -0700813 const auto *pipeline_creation_cache_control_features =
814 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
815 if (pipeline_creation_cache_control_features) {
816 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
817 }
sfricke-samsungfd661d62020-05-16 00:57:27 -0700818
sfricke-samsung828e59d2021-08-22 23:20:49 -0700819 const auto *fragment_shading_rate_features =
820 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
821 if (fragment_shading_rate_features) {
822 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
823 }
Tobias Hector6663c9b2020-11-05 10:18:02 +0000824
sfricke-samsung828e59d2021-08-22 23:20:49 -0700825 const auto *extended_dynamic_state_features =
826 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
827 if (extended_dynamic_state_features) {
828 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
829 }
Piers Daniell39842ee2020-07-10 16:42:33 -0600830
sfricke-samsung828e59d2021-08-22 23:20:49 -0700831 const auto *extended_dynamic_state2_features =
832 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
833 if (extended_dynamic_state2_features) {
834 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
835 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -0700836
sfricke-samsung828e59d2021-08-22 23:20:49 -0700837 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
838 if (multiview_features) {
839 state_tracker->enabled_features.multiview_features = *multiview_features;
840 }
locke-lunarg3fa463a2020-10-23 16:39:04 -0600841
sfricke-samsung828e59d2021-08-22 23:20:49 -0700842 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
843 if (portability_features) {
844 state_tracker->enabled_features.portability_subset_features = *portability_features;
845 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -0700846
sfricke-samsung828e59d2021-08-22 23:20:49 -0700847 const auto *shader_integer_functions2_features =
848 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
849 if (shader_integer_functions2_features) {
850 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
851 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800852
sfricke-samsung828e59d2021-08-22 23:20:49 -0700853 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
854 if (shader_sm_builtins_features) {
855 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
856 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800857
sfricke-samsung828e59d2021-08-22 23:20:49 -0700858 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
859 if (shader_atomic_float_features) {
860 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
861 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800862
sfricke-samsung828e59d2021-08-22 23:20:49 -0700863 const auto *shader_image_atomic_int64_features =
864 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
865 if (shader_image_atomic_int64_features) {
866 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
867 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800868
sfricke-samsung828e59d2021-08-22 23:20:49 -0700869 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
870 if (shader_clock_features) {
871 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
872 }
sfricke-samsung486a51e2021-01-02 00:10:15 -0800873
sfricke-samsung828e59d2021-08-22 23:20:49 -0700874 const auto *conditional_rendering_features =
875 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
876 if (conditional_rendering_features) {
877 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
878 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -0700879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *workgroup_memory_explicit_layout_features =
881 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
882 if (workgroup_memory_explicit_layout_features) {
883 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
884 }
Shannon McPhersondb287d42021-02-02 15:27:32 -0700885
sfricke-samsung828e59d2021-08-22 23:20:49 -0700886 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext);
887 if (synchronization2_features) {
888 state_tracker->enabled_features.synchronization2_features = *synchronization2_features;
889 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -0700890
sfricke-samsung828e59d2021-08-22 23:20:49 -0700891 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
892 if (provoking_vertex_features) {
893 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
894 }
Locke Linf3873542021-04-26 11:25:10 -0600895
sfricke-samsung828e59d2021-08-22 23:20:49 -0700896 const auto *vertex_input_dynamic_state_features =
897 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
898 if (vertex_input_dynamic_state_features) {
899 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
900 }
Piers Daniellcb6d8032021-04-19 18:51:26 -0600901
sfricke-samsung828e59d2021-08-22 23:20:49 -0700902 const auto *inherited_viewport_scissor_features =
903 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
904 if (inherited_viewport_scissor_features) {
905 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
906 }
David Zhao Akeley44139b12021-04-26 16:16:13 -0700907
sfricke-samsung828e59d2021-08-22 23:20:49 -0700908 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
909 if (multi_draw_features) {
910 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
911 }
Tony-LunarG4490de42021-06-21 15:49:19 -0600912
sfricke-samsung828e59d2021-08-22 23:20:49 -0700913 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
914 if (color_write_features) {
915 state_tracker->enabled_features.color_write_features = *color_write_features;
916 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +0200917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *shader_atomic_float2_features =
919 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
920 if (shader_atomic_float2_features) {
921 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
922 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -0700923
sfricke-samsung828e59d2021-08-22 23:20:49 -0700924 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
925 if (present_id_features) {
926 state_tracker->enabled_features.present_id_features = *present_id_features;
927 }
Tony-LunarG6f887e52021-07-27 11:23:14 -0600928
sfricke-samsung828e59d2021-08-22 23:20:49 -0700929 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
930 if (present_wait_features) {
931 state_tracker->enabled_features.present_wait_features = *present_wait_features;
932 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -0700933
934 const auto *ray_tracing_motion_blur_features =
935 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
936 if (ray_tracing_motion_blur_features) {
937 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
938 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -0700939
940 const auto *shader_integer_dot_product_features =
941 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
942 if (shader_integer_dot_product_features) {
943 state_tracker->enabled_features.shader_integer_dot_product_features = *shader_integer_dot_product_features;
944 }
Tony-LunarG0b0d8be2021-08-30 13:50:38 -0600945
946 const auto *primitive_topology_list_restart_features =
947 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
948 if (primitive_topology_list_restart_features) {
949 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
950 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -0700951
952 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
953 if (rgba10x6_formats_features) {
954 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
955 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -0700956
957 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
958 if (maintenance4_features) {
959 state_tracker->enabled_features.maintenance4_features = *maintenance4_features;
960 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -0700961
962 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(pCreateInfo->pNext);
963 if (dynamic_rendering_features) {
964 state_tracker->enabled_features.dynamic_rendering_features = *dynamic_rendering_features;
965 }
Tony-LunarG69604c42021-11-22 16:00:12 -0700966
967 const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
968 if (image_view_min_lod_features) {
969 state_tracker->enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
970 }
Tony-LunarG6f887e52021-07-27 11:23:14 -0600971 }
972
ziga-lunarg73163742021-08-25 13:15:29 +0200973 const auto *subgroup_size_control_features = LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeaturesEXT>(pCreateInfo->pNext);
974 if (subgroup_size_control_features) {
975 state_tracker->enabled_features.subgroup_size_control_features = *subgroup_size_control_features;
976 }
977
locke-lunargd556cc32019-09-17 01:21:23 -0600978 // Store physical device properties and physical device mem limits into CoreChecks structs
979 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
980 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
981
982 const auto &dev_ext = state_tracker->device_extensions;
983 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
984
sfricke-samsung828e59d2021-08-22 23:20:49 -0700985 // Vulkan 1.2 can get properties from single struct, otherwise need to add to it per extension
sfricke-samsung45996a42021-09-16 13:45:27 -0700986 if (dev_ext.vk_feature_version_1_2) {
987 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
988 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
sfricke-samsung828e59d2021-08-22 23:20:49 -0700989 } else {
990 // VkPhysicalDeviceVulkan11Properties
991 //
992 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
993
994 if (dev_ext.vk_khr_multiview) {
995 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
996 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
997 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
998 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
999 }
1000
1001 if (dev_ext.vk_khr_maintenance3) {
1002 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1003 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1004 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1005 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1006 }
1007
1008 // Some 1.1 properties were added to core without previous extensions
1009 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1010 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1011 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1012 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1013 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1014
1015 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1016 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1017 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1018 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1019
1020 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1021 }
1022
1023 // VkPhysicalDeviceVulkan12Properties
1024 //
1025 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1026
1027 if (dev_ext.vk_ext_descriptor_indexing) {
1028 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1029 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1030 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1031 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1032 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1033 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1034 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1035 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1036 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1037 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1038 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1039 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1040 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1041 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1042 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1043 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1044 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1045 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1046 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1047 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1048 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1049 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1050 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1051 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1052 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1053 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1054 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1055 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1056 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1057 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1058 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1059 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1060 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1061 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1062 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1063 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1064 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1065 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1066 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1067 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1068 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1069 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1070 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1071 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1072 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1073 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1074 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1075 }
1076
1077 if (dev_ext.vk_khr_depth_stencil_resolve) {
1078 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1079 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1080 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1081 depth_stencil_resolve_props.supportedDepthResolveModes;
1082 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1083 depth_stencil_resolve_props.supportedStencilResolveModes;
1084 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1085 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1086 }
1087
1088 if (dev_ext.vk_khr_timeline_semaphore) {
1089 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1090 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1091 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1092 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1093 }
1094
1095 if (dev_ext.vk_ext_sampler_filter_minmax) {
1096 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1097 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1098 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1099 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1100 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1101 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1102 }
1103
1104 if (dev_ext.vk_khr_shader_float_controls) {
1105 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1106 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1107 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1108 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1109 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1110 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1111 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1112 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1113 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1114 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1115 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1116 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1117 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1118 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1119 float_controls_props.shaderDenormFlushToZeroFloat16;
1120 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1121 float_controls_props.shaderDenormFlushToZeroFloat32;
1122 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1123 float_controls_props.shaderDenormFlushToZeroFloat64;
1124 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1125 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1126 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1127 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1128 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1129 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1130 }
locke-lunargd556cc32019-09-17 01:21:23 -06001131 }
1132
sfricke-samsung828e59d2021-08-22 23:20:49 -07001133 // Extensions with properties to extract to DeviceExtensionProperties
1134 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001135 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1136 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1137 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1138 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001139 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001140 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001141 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1142 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001143 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1144 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001145 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001146 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001147 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001148 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001149 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001150 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001151 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001152 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001153 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001154 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001155 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001156 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001157 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001158
sfricke-samsung45996a42021-09-16 13:45:27 -07001159 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001160 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001161 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1162 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001163 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1164 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1165
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001166 uint32_t num_cooperative_matrix_properties = 0;
1167 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1168 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001169 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001170
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001171 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001172 state_tracker->cooperative_matrix_properties.data());
1173 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001174
locke-lunargd556cc32019-09-17 01:21:23 -06001175 // Store queue family data
1176 if (pCreateInfo->pQueueCreateInfos != nullptr) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001177 uint32_t total_count = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001178 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001179 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001180 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1181 state_tracker->device_queue_info_list.push_back(
1182 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001183 total_count += queue_create_info.queueCount;
1184 }
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001185 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1186 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1187 VkQueue queue = VK_NULL_HANDLE;
1188 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1189 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1190 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1191 get_info.flags = queue_info.flags;
1192 get_info.queueFamilyIndex = queue_info.queue_family_index;
1193 get_info.queueIndex = i;
1194 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1195 } else {
1196 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1197 }
1198 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001199 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001200 }
locke-lunargd556cc32019-09-17 01:21:23 -06001201 }
1202 }
1203}
1204
1205void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1206 if (!device) return;
1207
Jeremy Gebbend177d922021-10-28 13:42:10 -06001208 command_pool_map_.clear();
1209 assert(command_buffer_map_.empty());
1210 pipeline_map_.clear();
1211 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001212
1213 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001214 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001215 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001216 assert(descriptor_set_map_.empty());
1217 desc_template_map_.clear();
1218 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001219 // Because swapchains are associated with Surfaces, which are at instance level,
1220 // they need to be explicitly destroyed here to avoid continued references to
1221 // the device we're destroying.
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001222 for (auto &entry : swapchain_map_.snapshot()) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001223 entry.second->Destroy();
1224 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001225 swapchain_map_.clear();
1226 image_view_map_.clear();
1227 image_map_.clear();
1228 buffer_view_map_.clear();
1229 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001230 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001231 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001232}
1233
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001234void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1235 VkFence fence, VkResult result) {
1236 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001237 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001238
Jeremy Gebben57642982021-09-14 14:14:55 -06001239 uint64_t early_retire_seq = 0;
1240
1241 if (submitCount == 0) {
1242 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001243 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001244 early_retire_seq = queue_state->Submit(std::move(submission));
1245 }
locke-lunargd556cc32019-09-17 01:21:23 -06001246
1247 // Now process each individual submit
1248 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001249 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001250 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001251 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001252 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001253 uint64_t value = 0;
1254 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1255 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1256 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1257 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001258 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001259 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001260
locke-lunargd556cc32019-09-17 01:21:23 -06001261 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001262 uint64_t value = 0;
1263 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1264 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1265 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1266 }
Jeremy Gebben9f537102021-10-05 16:37:12 -06001267 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001268 }
1269
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001270 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001271 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001272
locke-lunargd556cc32019-09-17 01:21:23 -06001273 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001274 submission.AddCommandBuffer(Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001275 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001276 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001277 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001278 }
1279 auto submit_seq = queue_state->Submit(std::move(submission));
1280 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001281 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001282
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001283 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001284 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001285 }
1286}
1287
1288void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1289 VkFence fence, VkResult result) {
1290 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001291 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001292 uint64_t early_retire_seq = 0;
1293 if (submitCount == 0) {
1294 CB_SUBMISSION submission;
Jeremy Gebben9f537102021-10-05 16:37:12 -06001295 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001296 early_retire_seq = queue_state->Submit(std::move(submission));
1297 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001298
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001299 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1300 CB_SUBMISSION submission;
1301 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001302 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1303 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001304 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001305 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001306 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1307 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben9f537102021-10-05 16:37:12 -06001308 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001309 }
1310 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1311 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1312
1313 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001314 submission.AddCommandBuffer(Get<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001315 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001316 if (submit_idx == (submitCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001317 submission.AddFence(Get<FENCE_STATE>(fence));
Jeremy Gebben57642982021-09-14 14:14:55 -06001318 }
1319 auto submit_seq = queue_state->Submit(std::move(submission));
1320 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001321 }
locke-lunargd556cc32019-09-17 01:21:23 -06001322 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001323 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001324 }
1325}
1326
1327void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1328 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1329 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001330 if (VK_SUCCESS != result) {
1331 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001332 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001333 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1334 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1335 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1336
1337 layer_data::optional<DedicatedBinding> dedicated_binding;
1338
1339 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1340 if (dedicated) {
1341 if (dedicated->buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001342 const auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001343 assert(buffer_state);
1344 if (!buffer_state) {
1345 return;
1346 }
1347 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1348 } else if (dedicated->image) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001349 const auto image_state = Get<IMAGE_STATE>(dedicated->image);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001350 assert(image_state);
1351 if (!image_state) {
1352 return;
1353 }
1354 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1355 }
1356 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001357 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1358 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001359 return;
1360}
1361
1362void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001363 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001364 if (mem_info) {
1365 fake_memory.Free(mem_info->fake_base_address);
1366 }
1367 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001368}
1369
1370void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1371 VkFence fence, VkResult result) {
1372 if (result != VK_SUCCESS) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001373 auto queue_state = Get<QUEUE_STATE>(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001374
Jeremy Gebben57642982021-09-14 14:14:55 -06001375 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001376
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001377 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1378 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001379 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001380 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1381 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1382 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001383 auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001384 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001385 if (buffer_state && mem_state) {
1386 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1387 }
locke-lunargd556cc32019-09-17 01:21:23 -06001388 }
1389 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001390 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1391 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1392 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001393 auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001394 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001395 if (image_state && mem_state) {
1396 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1397 }
locke-lunargd556cc32019-09-17 01:21:23 -06001398 }
1399 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001400 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1401 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1402 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001403 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1404 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001405 auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
Jeremy Gebben9f537102021-10-05 16:37:12 -06001406 auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001407 if (image_state && mem_state) {
1408 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1409 }
locke-lunargd556cc32019-09-17 01:21:23 -06001410 }
1411 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001412 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001413 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001414 submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001415 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001416 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001417 submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001418 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001419 if (bind_idx == (bindInfoCount - 1)) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001420 submission.AddFence(Get<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001421 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001422 auto submit_seq = queue_state->Submit(std::move(submission));
1423 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001424 }
1425
1426 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001427 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001428 }
1429}
1430
1431void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1432 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1433 VkResult result) {
1434 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001435 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001436}
1437
Mike Schuchardt2df08912020-12-15 16:28:09 -08001438void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1439 VkSemaphoreImportFlags flags) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001440 auto sema_node = Get<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001441 if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001442 if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06001443 sema_node->scope == kSyncScopeInternal) {
1444 sema_node->scope = kSyncScopeExternalTemporary;
1445 } else {
1446 sema_node->scope = kSyncScopeExternalPermanent;
1447 }
1448 }
1449}
1450
Mike Schuchardt2df08912020-12-15 16:28:09 -08001451void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001452 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001453 auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001454 semaphore_state->payload = pSignalInfo->value;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001455}
1456
locke-lunargd556cc32019-09-17 01:21:23 -06001457void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001458 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001459 if (mem_info) {
1460 mem_info->mapped_range.offset = offset;
1461 mem_info->mapped_range.size = size;
1462 mem_info->p_driver_data = *ppData;
1463 }
1464}
1465
locke-lunargd556cc32019-09-17 01:21:23 -06001466void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1467 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1468 if (VK_SUCCESS != result) return;
1469
1470 // When we know that all fences are complete we can clean/remove their CBs
1471 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1472 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001473 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001474 if (fence_state) {
1475 fence_state->Retire();
1476 }
locke-lunargd556cc32019-09-17 01:21:23 -06001477 }
1478 }
1479 // NOTE : Alternate case not handled here is when some fences have completed. In
1480 // this case for app to guarantee which fences completed it will have to call
1481 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1482}
1483
John Zulauff89de662020-04-13 18:57:34 -06001484void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1485 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001486 if (VK_SUCCESS != result) return;
1487
1488 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001489 auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
Jeremy Gebben57642982021-09-14 14:14:55 -06001490 if (semaphore_state) {
1491 semaphore_state->Retire(pWaitInfo->pValues[i]);
1492 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001493 }
1494}
1495
John Zulauff89de662020-04-13 18:57:34 -06001496void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1497 VkResult result) {
1498 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1499}
1500
1501void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1502 uint64_t timeout, VkResult result) {
1503 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1504}
1505
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001506void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1507 VkResult result) {
1508 if (VK_SUCCESS != result) return;
1509
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001510 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Jeremy Gebben57642982021-09-14 14:14:55 -06001511 if (semaphore_state) {
1512 semaphore_state->Retire(*pValue);
1513 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001514}
1515
1516void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1517 VkResult result) {
1518 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1519}
1520void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1521 VkResult result) {
1522 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1523}
1524
locke-lunargd556cc32019-09-17 01:21:23 -06001525void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1526 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001527 auto fence_state = Get<FENCE_STATE>(fence);
Jeremy Gebben57642982021-09-14 14:14:55 -06001528 if (fence_state) {
1529 fence_state->Retire();
1530 }
locke-lunargd556cc32019-09-17 01:21:23 -06001531}
1532
Yilong Lice03a312022-01-02 02:08:35 -08001533void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
1534 if (Get<QUEUE_STATE>(queue) == nullptr) {
1535 Add(std::make_shared<QUEUE_STATE>(queue, queue_family_index, flags));
1536 }
1537}
1538
1539void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1540 VkQueue *pQueue) {
1541 RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
1542}
1543
1544void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1545 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
1546}
1547
locke-lunargd556cc32019-09-17 01:21:23 -06001548void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1549 if (VK_SUCCESS != result) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001550 auto queue_state = Get<QUEUE_STATE>(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001551 if (queue_state) {
1552 queue_state->Retire();
1553 }
locke-lunargd556cc32019-09-17 01:21:23 -06001554}
1555
1556void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1557 if (VK_SUCCESS != result) return;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06001558 for (auto &queue : queue_map_.snapshot()) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001559 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001560 }
1561}
1562
1563void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001564 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001565}
1566
1567void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1568 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001569 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001570}
1571
1572void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001573 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001574}
1575
1576void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1577 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001578 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001579}
1580
locke-lunargd556cc32019-09-17 01:21:23 -06001581void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001582 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001583 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001584 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06001585 auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001586 if (mem_state) {
1587 buffer_state->SetMemBinding(mem_state, memoryOffset);
1588 }
locke-lunargd556cc32019-09-17 01:21:23 -06001589 }
1590}
1591
1592void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1593 VkDeviceSize memoryOffset, VkResult result) {
1594 if (VK_SUCCESS != result) return;
1595 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1596}
1597
1598void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001599 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001600 for (uint32_t i = 0; i < bindInfoCount; i++) {
1601 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1602 }
1603}
1604
1605void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001606 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001607 for (uint32_t i = 0; i < bindInfoCount; i++) {
1608 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1609 }
1610}
1611
Spencer Fricke6c127102020-04-16 06:25:20 -07001612void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001613 auto buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001614 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001615 buffer_state->memory_requirements_checked = true;
1616 }
1617}
1618
1619void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1620 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001621 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001622}
1623
1624void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001625 const VkBufferMemoryRequirementsInfo2 *pInfo,
1626 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001627 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001628}
1629
1630void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001631 const VkBufferMemoryRequirementsInfo2 *pInfo,
1632 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001633 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001634}
1635
Spencer Fricke6c127102020-04-16 06:25:20 -07001636void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001637 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001638 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001639 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001640 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001641 if (plane_info != nullptr) {
1642 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001643 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001644 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001645 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001646 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001647 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001648 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001649 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001650 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001651 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001652 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001653 }
locke-lunargd556cc32019-09-17 01:21:23 -06001654 }
1655}
1656
1657void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1658 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001659 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001660}
1661
1662void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1663 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001664 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001665}
1666
1667void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1668 const VkImageMemoryRequirementsInfo2 *pInfo,
1669 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001670 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001671}
1672
locke-lunargd556cc32019-09-17 01:21:23 -06001673void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1674 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1675 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001676 auto image_state = Get<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -06001677 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001678}
1679
1680void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001681 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1682 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001683 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001684 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001685}
1686
1687void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001688 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1689 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001690 auto image_state = Get<IMAGE_STATE>(pInfo->image);
locke-lunargd556cc32019-09-17 01:21:23 -06001691 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001692}
1693
1694void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1695 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001696 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001697}
1698
1699void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1700 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001701 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001702}
1703
1704void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1705 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001706 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001707}
1708
1709void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1710 const VkAllocationCallbacks *pAllocator) {
1711 if (!sampler) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001712 auto sampler_state = Get<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001713 // Any bound cmd buffers are now invalid
1714 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001715 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1716 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1717 custom_border_color_sampler_count--;
1718 }
locke-lunargd556cc32019-09-17 01:21:23 -06001719 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001720 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001721}
1722
1723void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1724 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001725 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001726}
1727
1728void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1729 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001730 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001731}
1732
locke-lunargd556cc32019-09-17 01:21:23 -06001733void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1734 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001735 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1736 if (pool) {
1737 pool->Free(commandBufferCount, pCommandBuffers);
1738 }
locke-lunargd556cc32019-09-17 01:21:23 -06001739}
1740
1741void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1742 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1743 VkResult result) {
1744 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001745 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001746 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001747}
1748
1749void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1750 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1751 VkResult result) {
1752 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001753
1754 uint32_t index_count = 0, n_perf_pass = 0;
1755 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001756 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001757 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001758 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001759
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001760 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001761 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1762 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1763 switch (counter.scope) {
1764 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001765 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001766 break;
1767 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001768 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001769 break;
1770 default:
1771 break;
1772 }
1773 }
1774
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001775 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001776 }
1777
Jeremy Gebben082a9832021-10-28 13:40:11 -06001778 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 -06001779
locke-lunargd556cc32019-09-17 01:21:23 -06001780}
1781
1782void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1783 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001784 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001785}
1786
1787void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
1788 VkCommandPoolResetFlags flags, VkResult result) {
1789 if (VK_SUCCESS != result) return;
1790 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001791 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1792 if (pool) {
1793 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001794 }
1795}
1796
1797void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1798 VkResult result) {
1799 for (uint32_t i = 0; i < fenceCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001800 auto fence_state = Get<FENCE_STATE>(pFences[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001801 if (fence_state) {
1802 if (fence_state->scope == kSyncScopeInternal) {
1803 fence_state->state = FENCE_UNSIGNALED;
1804 } else if (fence_state->scope == kSyncScopeExternalTemporary) {
1805 fence_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06001806 }
1807 }
1808 }
1809}
1810
locke-lunargd556cc32019-09-17 01:21:23 -06001811void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
1812 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001813 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001814}
1815
1816void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
1817 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001818 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06001819}
1820
1821void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
1822 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
1823 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001824 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001825}
1826
1827bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1828 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1829 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001830 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001831 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
1832 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1833 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1834 cgpl_state->pipe_state.reserve(count);
1835 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebbence23dac2021-11-10 10:19:42 -07001836 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001837 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
1838 Get<RENDER_PASS_STATE>(pCreateInfos[i].renderPass),
1839 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
amhagana448ea52021-11-02 14:09:14 -04001840 } else if (enabled_features.dynamic_rendering_features.dynamicRendering) {
1841 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfoKHR>(pCreateInfos[i].pNext);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001842 cgpl_state->pipe_state.push_back(
1843 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], std::make_shared<RENDER_PASS_STATE>(dynamic_rendering),
Jeremy Gebben9f537102021-10-05 16:37:12 -06001844 Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeremy Gebbence23dac2021-11-10 10:19:42 -07001845 }
locke-lunargd556cc32019-09-17 01:21:23 -06001846 }
1847 return false;
1848}
1849
1850void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1851 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1852 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
1853 VkResult result, void *cgpl_state_data) {
1854 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1855 // This API may create pipelines regardless of the return value
1856 for (uint32_t i = 0; i < count; i++) {
1857 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001858 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001859 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001860 }
1861 }
1862 cgpl_state->pipe_state.clear();
1863}
1864
1865bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1866 const VkComputePipelineCreateInfo *pCreateInfos,
1867 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001868 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001869 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
1870 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1871 ccpl_state->pipe_state.reserve(count);
1872 for (uint32_t i = 0; i < count; i++) {
1873 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001874 ccpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06001875 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06001876 }
1877 return false;
1878}
1879
1880void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1881 const VkComputePipelineCreateInfo *pCreateInfos,
1882 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
1883 VkResult result, void *ccpl_state_data) {
1884 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
1885
1886 // This API may create pipelines regardless of the return value
1887 for (uint32_t i = 0; i < count; i++) {
1888 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001889 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001890 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001891 }
1892 }
1893 ccpl_state->pipe_state.clear();
1894}
1895
1896bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
1897 uint32_t count,
1898 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1899 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001900 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001901 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
1902 crtpl_state->pipe_state.reserve(count);
1903 for (uint32_t i = 0; i < count; i++) {
1904 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001905 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06001906 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06001907 }
1908 return false;
1909}
1910
1911void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
1912 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1913 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
1914 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
1915 // This API may create pipelines regardless of the return value
1916 for (uint32_t i = 0; i < count; i++) {
1917 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001918 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001919 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001920 }
1921 }
1922 crtpl_state->pipe_state.clear();
1923}
1924
sourav parmarcd5fb182020-07-17 12:58:44 -07001925bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
1926 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001927 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
1928 const VkAllocationCallbacks *pAllocator,
1929 VkPipeline *pPipelines, void *crtpl_state_data) const {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001930 auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001931 crtpl_state->pipe_state.reserve(count);
1932 for (uint32_t i = 0; i < count; i++) {
1933 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001934 crtpl_state->pipe_state.push_back(
Jeremy Gebben9f537102021-10-05 16:37:12 -06001935 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001936 }
1937 return false;
1938}
1939
sourav parmarcd5fb182020-07-17 12:58:44 -07001940void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
1941 VkPipelineCache pipelineCache, uint32_t count,
1942 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
1943 const VkAllocationCallbacks *pAllocator,
1944 VkPipeline *pPipelines, VkResult result,
1945 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001946 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
1947 // This API may create pipelines regardless of the return value
1948 for (uint32_t i = 0; i < count; i++) {
1949 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001950 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001951 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001952 }
1953 }
1954 crtpl_state->pipe_state.clear();
1955}
1956
locke-lunargd556cc32019-09-17 01:21:23 -06001957void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
1958 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
1959 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001960 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001961 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1962 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06001963 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001964 }
locke-lunargd556cc32019-09-17 01:21:23 -06001965}
1966
1967void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
1968 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1969 const VkAllocationCallbacks *pAllocator,
1970 VkDescriptorSetLayout *pSetLayout, VkResult result) {
1971 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001972 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06001973}
1974
locke-lunargd556cc32019-09-17 01:21:23 -06001975void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
1976 const VkAllocationCallbacks *pAllocator,
1977 VkPipelineLayout *pPipelineLayout, VkResult result) {
1978 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001979 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001980}
1981
1982void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
1983 const VkAllocationCallbacks *pAllocator,
1984 VkDescriptorPool *pDescriptorPool, VkResult result) {
1985 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001986 Add(std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001987}
1988
1989void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1990 VkDescriptorPoolResetFlags flags, VkResult result) {
1991 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06001992 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
1993 if (pool) {
1994 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001995 }
locke-lunargd556cc32019-09-17 01:21:23 -06001996}
1997
1998bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
1999 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002000 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002001 // Always update common data
2002 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2003 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2004 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2005
2006 return false;
2007}
2008
2009// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2010void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2011 VkDescriptorSet *pDescriptorSets, VkResult result,
2012 void *ads_state_data) {
2013 if (VK_SUCCESS != result) return;
2014 // All the updates are contained in a single cvdescriptorset function
2015 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2016 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002017 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2018 if (pool_state) {
2019 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2020 }
locke-lunargd556cc32019-09-17 01:21:23 -06002021}
2022
2023void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2024 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002025 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2026 if (pool_state) {
2027 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002028 }
2029}
2030
2031void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2032 const VkWriteDescriptorSet *pDescriptorWrites,
2033 uint32_t descriptorCopyCount,
2034 const VkCopyDescriptorSet *pDescriptorCopies) {
2035 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2036 pDescriptorCopies);
2037}
2038
2039void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002040 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002041 if (VK_SUCCESS != result) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06002042 auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002043 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002044 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002045 }
2046}
2047
locke-lunargd556cc32019-09-17 01:21:23 -06002048void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2049 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002050 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002051 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002052
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002053 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002054}
2055
2056void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002057 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002058 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002059
2060 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002061}
2062
2063void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2064 VkResult result) {
2065 if (VK_SUCCESS == result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002066 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002067 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002068 }
2069}
2070
2071CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2072 // initially assume everything is static state
2073 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2074
2075 if (ds) {
2076 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002077 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002078 }
2079 }
locke-lunargd556cc32019-09-17 01:21:23 -06002080 return flags;
2081}
2082
2083// Validation cache:
2084// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002085
2086void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2087 VkPipeline pipeline) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002088 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002089 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002090 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002091
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002092 auto pipe_state = Get<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002093 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002094 const auto &create_info = pipe_state->create_info.graphics;
2095 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2096 const auto *viewport_state = create_info.pViewportState;
2097 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002098 cb_state->status &= ~cb_state->static_status;
Yilong Lid23bc292022-01-02 22:06:12 -08002099 cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002100 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002101 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002102
2103 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002104 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2105 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002106 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002107 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002108 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002109 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002110 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002111 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002112
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002113 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002114 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2115 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2116 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002117 if (!has_dynamic_viewport_count) {
2118 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002119 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002120 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2121 // should become = ~uint32_t(0) if the other interpretation is correct.
2122 }
2123 }
2124 if (!has_dynamic_scissor_count) {
2125 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002126 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002127 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2128 // should become = ~uint32_t(0) if the other interpretation is correct.
2129 }
2130 }
locke-lunargd556cc32019-09-17 01:21:23 -06002131 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002132 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002133 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state.get();
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002134 if (!disabled[command_buffer_state]) {
2135 cb_state->AddChild(pipe_state);
2136 }
locke-lunargd556cc32019-09-17 01:21:23 -06002137}
2138
2139void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2140 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002141 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002142 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002143 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2144 cb_state->viewportMask |= bits;
2145 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002146
2147 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2148 for (size_t i = 0; i < viewportCount; ++i) {
2149 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2150 }
locke-lunargd556cc32019-09-17 01:21:23 -06002151}
2152
2153void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2154 uint32_t exclusiveScissorCount,
2155 const VkRect2D *pExclusiveScissors) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002156 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002157 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002158 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2159 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002160}
2161
2162void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2163 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002164 if (disabled[command_buffer_state]) return;
2165
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002166 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002167 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002168
2169 if (imageView != VK_NULL_HANDLE) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002170 auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002171 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002172 }
2173}
2174
2175void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2176 uint32_t viewportCount,
2177 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002178 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002179 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002180 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2181 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002182}
2183
2184void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2185 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2186 const VkAllocationCallbacks *pAllocator,
2187 VkAccelerationStructureNV *pAccelerationStructure,
2188 VkResult result) {
2189 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002190 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002191
2192 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002193 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002194 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002195 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002196 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2197
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002198 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002199 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002200 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002201 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2202 &as_state->build_scratch_memory_requirements);
2203
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002204 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002205 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002206 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002207 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2208 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002209 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002210 Add(std::move(as_state));
locke-lunargd556cc32019-09-17 01:21:23 -06002211}
2212
Jeff Bolz95176d02020-04-01 00:36:16 -05002213void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2214 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2215 const VkAllocationCallbacks *pAllocator,
2216 VkAccelerationStructureKHR *pAccelerationStructure,
2217 VkResult result) {
2218 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002219 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002220 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002221 Add(std::move(as_state));
Jeff Bolz95176d02020-04-01 00:36:16 -05002222}
2223
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002224void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2225 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2226 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2227 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2228 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002229 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002230 if (dst_as_state != nullptr) {
2231 dst_as_state->Build(&pInfos[i]);
2232 }
2233 }
2234}
2235
sourav parmarcd5fb182020-07-17 12:58:44 -07002236void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2237 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2238 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002239 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002240 if (!cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002241 return;
2242 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002243 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002244 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002245 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002246 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002247 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002248 if (!disabled[command_buffer_state]) {
2249 cb_state->AddChild(dst_as_state);
2250 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002251 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002252 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002253 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002254 if (src_as_state != nullptr) {
2255 cb_state->AddChild(src_as_state);
2256 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002257 }
2258 }
2259 cb_state->hasBuildAccelerationStructureCmd = true;
2260}
2261
2262void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2263 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2264 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2265 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002266 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002267 if (cb_state == nullptr) {
2268 return;
2269 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002270 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002271 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002272 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002273 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002274 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002275 if (!disabled[command_buffer_state]) {
2276 cb_state->AddChild(dst_as_state);
2277 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002278 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002279 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002280 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].srcAccelerationStructure);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002281 if (src_as_state != nullptr) {
2282 cb_state->AddChild(src_as_state);
2283 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002284 }
2285 }
2286 cb_state->hasBuildAccelerationStructureCmd = true;
2287}
locke-lunargd556cc32019-09-17 01:21:23 -06002288void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002289 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002290 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002291 if (as_state != nullptr) {
2292 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2293 as_state->memory_requirements = *pMemoryRequirements;
2294 as_state->memory_requirements_checked = true;
2295 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2296 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2297 as_state->build_scratch_memory_requirements_checked = true;
2298 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2299 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2300 as_state->update_scratch_memory_requirements_checked = true;
2301 }
2302 }
2303}
2304
sourav parmarcd5fb182020-07-17 12:58:44 -07002305void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2306 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002307 if (VK_SUCCESS != result) return;
2308 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002309 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002310
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002311 auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002312 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002313 // Track objects tied to memory
Jeremy Gebben9f537102021-10-05 16:37:12 -06002314 auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002315 if (mem_state) {
2316 as_state->SetMemBinding(mem_state, info.memoryOffset);
2317 }
locke-lunargd556cc32019-09-17 01:21:23 -06002318
2319 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002320 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002321 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002322 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2323 }
2324 }
2325 }
2326}
2327
2328void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2329 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2330 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002331 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002332 if (cb_state == nullptr) {
2333 return;
2334 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002335 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002336
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002337 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002338 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002339 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002340 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002341 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002342 }
locke-lunargd556cc32019-09-17 01:21:23 -06002343 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002344 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002345 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002346 if (src_as_state != nullptr) {
2347 cb_state->AddChild(src_as_state);
2348 }
locke-lunargd556cc32019-09-17 01:21:23 -06002349 }
2350 cb_state->hasBuildAccelerationStructureCmd = true;
2351}
2352
2353void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2354 VkAccelerationStructureNV dst,
2355 VkAccelerationStructureNV src,
2356 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002357 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002358 if (cb_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002359 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
2360 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002361 if (!disabled[command_buffer_state]) {
2362 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2363 }
locke-lunargd556cc32019-09-17 01:21:23 -06002364 if (dst_as_state != nullptr && src_as_state != nullptr) {
2365 dst_as_state->built = true;
2366 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002367 }
2368 }
2369}
2370
Jeff Bolz95176d02020-04-01 00:36:16 -05002371void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2372 VkAccelerationStructureKHR accelerationStructure,
2373 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002374 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002375}
2376
Jeff Bolz95176d02020-04-01 00:36:16 -05002377void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2378 VkAccelerationStructureNV accelerationStructure,
2379 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002380 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002381}
2382
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002383void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2384 uint32_t viewportCount,
2385 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002386 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002387 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002388}
2389
locke-lunargd556cc32019-09-17 01:21:23 -06002390void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002391 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002392 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002393}
2394
2395void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2396 uint16_t lineStipplePattern) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002397 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002398 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002399}
2400
2401void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2402 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002403 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002404 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002405}
2406
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002407void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2408 const VkRect2D *pScissors) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002409 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002410 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002411 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2412 cb_state->scissorMask |= bits;
2413 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002414}
2415
locke-lunargd556cc32019-09-17 01:21:23 -06002416void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002417 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002418 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002419}
2420
2421void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2422 float maxDepthBounds) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002423 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002424 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002425}
2426
2427void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2428 uint32_t compareMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002429 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002430 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002431}
2432
2433void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2434 uint32_t writeMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002435 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002436 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002437}
2438
2439void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2440 uint32_t reference) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002441 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002442 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002443}
2444
locke-lunargd556cc32019-09-17 01:21:23 -06002445// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2446void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2447 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2448 uint32_t firstSet, uint32_t setCount,
2449 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2450 const uint32_t *pDynamicOffsets) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002451 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002452 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002453 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
locke-lunargd556cc32019-09-17 01:21:23 -06002454
Jeremy Gebben9f537102021-10-05 16:37:12 -06002455 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout.get(), firstSet, setCount, pDescriptorSets, nullptr,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002456 dynamicOffsetCount, pDynamicOffsets);
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002457}
2458
locke-lunargd556cc32019-09-17 01:21:23 -06002459void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2460 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2461 uint32_t set, uint32_t descriptorWriteCount,
2462 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002463 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2464 auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002465 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout.get(), set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002466}
2467
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002468void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2469 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2470 const void *pValues) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002471 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002472 if (cb_state != nullptr) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002473 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002474 auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
2475 cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002476
2477 auto &push_constant_data = cb_state->push_constant_data;
2478 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2479 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002480 cb_state->push_constant_pipeline_layout_set = layout;
2481
2482 auto flags = stageFlags;
2483 uint32_t bit_shift = 0;
2484 while (flags) {
2485 if (flags & 1) {
2486 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2487 const auto it = cb_state->push_constant_data_update.find(flag);
2488
2489 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002490 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002491 }
2492 }
2493 flags = flags >> 1;
2494 ++bit_shift;
2495 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002496 }
2497}
2498
locke-lunargd556cc32019-09-17 01:21:23 -06002499void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2500 VkIndexType indexType) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002501 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002502
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002503 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
Jeremy Gebben9f537102021-10-05 16:37:12 -06002504 cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002505 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002506 cb_state->index_buffer_binding.offset = offset;
2507 cb_state->index_buffer_binding.index_type = indexType;
2508 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002509 if (!disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002510 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002511 }
locke-lunargd556cc32019-09-17 01:21:23 -06002512}
2513
2514void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2515 uint32_t bindingCount, const VkBuffer *pBuffers,
2516 const VkDeviceSize *pOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002517 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002518 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002519
2520 uint32_t end = firstBinding + bindingCount;
2521 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2522 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2523 }
2524
2525 for (uint32_t i = 0; i < bindingCount; ++i) {
2526 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06002527 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002528 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002529 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2530 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002531 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002532 if (pBuffers[i] && !disabled[command_buffer_state]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002533 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Jeff Bolz165818a2020-05-08 11:19:03 -05002534 }
locke-lunargd556cc32019-09-17 01:21:23 -06002535 }
2536}
2537
2538void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2539 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002540 if (disabled[command_buffer_state]) return;
2541
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002542 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002543 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002544}
2545
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002546void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2547 VkPipelineStageFlags stageMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002548 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002549 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002550}
2551
2552void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2553 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002554 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002555 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2556
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002557 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2558 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002559}
2560
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002561void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2562 VkPipelineStageFlags stageMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002563 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002564 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002565}
2566
2567void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2568 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002569 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002570 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002571}
2572
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002573void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2574 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2575 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2576 uint32_t bufferMemoryBarrierCount,
2577 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2578 uint32_t imageMemoryBarrierCount,
2579 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002580 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002581 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
2582 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2583 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002584}
2585
2586void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2587 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002588 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002589 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
Jeremy Gebben79649152021-06-22 14:46:24 -06002590 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002591 cb_state->RecordBarriers(pDependencyInfos[i]);
Jeremy Gebben79649152021-06-22 14:46:24 -06002592 }
2593}
2594
2595void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2596 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2597 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2598 uint32_t bufferMemoryBarrierCount,
2599 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2600 uint32_t imageMemoryBarrierCount,
2601 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002602 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2603 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2604 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2605 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002606}
2607
2608void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2609 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002610 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2611 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2612 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002613}
2614
locke-lunargd556cc32019-09-17 01:21:23 -06002615void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2616 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002617 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002618
locke-lunargd556cc32019-09-17 01:21:23 -06002619 QueryObject query = {queryPool, slot};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002620 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002621 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002622 if (!disabled[query_validation]) {
2623 cb_state->BeginQuery(query);
2624 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002625 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002626 auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002627 cb_state->AddChild(pool_state);
2628 }
locke-lunargd556cc32019-09-17 01:21:23 -06002629}
2630
2631void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002632 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002633 QueryObject query_obj = {queryPool, slot};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002634 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002635 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002636 if (!disabled[query_validation]) {
2637 cb_state->EndQuery(query_obj);
2638 }
2639 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002640 auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002641 cb_state->AddChild(pool_state);
2642 }
locke-lunargd556cc32019-09-17 01:21:23 -06002643}
2644
2645void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2646 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002647 if (disabled[query_validation]) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002648 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002649
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002650 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002651 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002652
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002653 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002654 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002655 cb_state->AddChild(pool_state);
2656 }
locke-lunargd556cc32019-09-17 01:21:23 -06002657}
2658
2659void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2660 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2661 VkDeviceSize dstOffset, VkDeviceSize stride,
2662 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002663 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2664
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002665 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002666 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002667 auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002668 cb_state->AddChild(dst_buff_state);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002669 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002670 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002671}
2672
2673void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2674 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002675 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002676 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002677}
2678
2679void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2680 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2681 uint32_t slot) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002682 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002683 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002684}
2685
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002686void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
2687 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
2688 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
2689 if (disabled[query_validation]) return;
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002690 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002691 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002692 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002693 auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002694 cb_state->AddChild(pool_state);
2695 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002696 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002697}
2698
locke-lunargd556cc32019-09-17 01:21:23 -06002699void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
2700 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
2701 VkResult result) {
2702 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002703
Jeremy Gebben88f58142021-06-01 10:07:52 -06002704 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002705 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002706 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002707
locke-lunargd556cc32019-09-17 01:21:23 -06002708 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002709 views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002710 }
2711 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06002712
Jeremy Gebben9f537102021-10-05 16:37:12 -06002713 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
Jeremy Gebben082a9832021-10-28 13:40:11 -06002714 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06002715}
2716
locke-lunargd556cc32019-09-17 01:21:23 -06002717void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
2718 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2719 VkResult result) {
2720 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002721 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002722}
2723
Mike Schuchardt2df08912020-12-15 16:28:09 -08002724void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002725 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2726 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002727 if (VK_SUCCESS != result) return;
2728
Jeremy Gebben082a9832021-10-28 13:40:11 -06002729 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002730}
2731
Mike Schuchardt2df08912020-12-15 16:28:09 -08002732void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002733 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2734 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002735 if (VK_SUCCESS != result) return;
2736
Jeremy Gebben082a9832021-10-28 13:40:11 -06002737 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002738}
2739
locke-lunargd556cc32019-09-17 01:21:23 -06002740void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
2741 const VkRenderPassBeginInfo *pRenderPassBegin,
2742 VkSubpassContents contents) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002743 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002744 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002745}
2746
2747void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
2748 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002749 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002750 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002751 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002752}
2753
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002754void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2755 uint32_t counterBufferCount,
2756 const VkBuffer *pCounterBuffers,
2757 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002758 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002759
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002760 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002761 cb_state->transform_feedback_active = true;
2762}
2763
2764void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2765 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
2766 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002767 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002768
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002769 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002770 cb_state->transform_feedback_active = false;
2771}
2772
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002773void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
2774 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002775 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002776
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002777 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002778 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002779 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
2780 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002781}
2782
2783void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002784 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002785
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002786 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002787 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002788 cb_state->conditional_rendering_inside_render_pass = false;
2789 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002790}
2791
amhagana448ea52021-11-02 14:09:14 -04002792void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002793 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04002794 cb_state->activeRenderPass = nullptr;
2795}
2796
2797void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
2798 const VkRenderingInfoKHR *pRenderingInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002799 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
amhagana448ea52021-11-02 14:09:14 -04002800 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
2801}
2802
2803void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
2804 RecordCmdEndRenderingRenderPassState(commandBuffer);
2805}
2806
Tony-LunarG977448c2019-12-02 14:52:02 -07002807void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
2808 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002809 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002810 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002811 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07002812}
2813
locke-lunargd556cc32019-09-17 01:21:23 -06002814void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002815 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002816 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002817}
2818
2819void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002820 const VkSubpassBeginInfo *pSubpassBeginInfo,
2821 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002822 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002823 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002824}
2825
Tony-LunarG977448c2019-12-02 14:52:02 -07002826void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002827 const VkSubpassBeginInfo *pSubpassBeginInfo,
2828 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002829 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002830 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002831}
2832
2833void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002834 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002835 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06002836}
2837
2838void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002839 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002840 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002841 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06002842}
2843
Tony-LunarG977448c2019-12-02 14:52:02 -07002844void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002845 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002846 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002847 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07002848}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002849
locke-lunargd556cc32019-09-17 01:21:23 -06002850void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
2851 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002852 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002853
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002854 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06002855}
2856
2857void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
2858 VkFlags flags, void **ppData, VkResult result) {
2859 if (VK_SUCCESS != result) return;
2860 RecordMappedMemory(mem, offset, size, ppData);
2861}
2862
2863void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002864 auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06002865 if (mem_info) {
2866 mem_info->mapped_range = MemRange();
2867 mem_info->p_driver_data = nullptr;
2868 }
2869}
2870
2871void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002872 auto image_state = Get<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06002873 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06002874 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
2875 // See: VUID-vkGetImageSubresourceLayout-image-01895
2876 image_state->fragment_encoder =
2877 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002878 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002879 if (swapchain_info) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06002880 auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06002881 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002882 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07002883
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002884 if (!swapchain_image.fake_base_address) {
2885 auto size = image_state->fragment_encoder->TotalSize();
2886 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002887 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002888 // All images bound to this swapchain and index are aliases
2889 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06002890 }
2891 } else {
2892 // Track bound memory range information
Jeremy Gebben9f537102021-10-05 16:37:12 -06002893 auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06002894 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002895 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06002896 }
locke-lunargd556cc32019-09-17 01:21:23 -06002897 }
locke-lunargd556cc32019-09-17 01:21:23 -06002898 }
2899}
2900
2901void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
2902 VkDeviceSize memoryOffset, VkResult result) {
2903 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002904 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002905 bind_info.image = image;
2906 bind_info.memory = mem;
2907 bind_info.memoryOffset = memoryOffset;
2908 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06002909}
2910
2911void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002912 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002913 if (VK_SUCCESS != result) return;
2914 for (uint32_t i = 0; i < bindInfoCount; i++) {
2915 UpdateBindImageMemoryState(pBindInfos[i]);
2916 }
2917}
2918
2919void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002920 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002921 if (VK_SUCCESS != result) return;
2922 for (uint32_t i = 0; i < bindInfoCount; i++) {
2923 UpdateBindImageMemoryState(pBindInfos[i]);
2924 }
2925}
2926
2927void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002928 auto event_state = Get<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06002929 if (event_state) {
2930 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
2931 }
locke-lunargd556cc32019-09-17 01:21:23 -06002932}
2933
2934void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
2935 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
2936 VkResult result) {
2937 if (VK_SUCCESS != result) return;
2938 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
2939 pImportSemaphoreFdInfo->flags);
2940}
2941
2942void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002943 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06002944 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Mike Schuchardt2df08912020-12-15 16:28:09 -08002945 if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06002946 // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference
2947 semaphore_state->scope = kSyncScopeExternalPermanent;
2948 }
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);
locke-lunargd556cc32019-09-17 01:21:23 -06002990 if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08002991 if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06002992 fence_node->scope == kSyncScopeInternal) {
2993 fence_node->scope = kSyncScopeExternalTemporary;
2994 } else {
2995 fence_node->scope = kSyncScopeExternalPermanent;
2996 }
2997 }
2998}
2999
3000void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3001 VkResult result) {
3002 if (VK_SUCCESS != result) return;
3003 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3004}
3005
Mike Schuchardt2df08912020-12-15 16:28:09 -08003006void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003007 auto fence_state = Get<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06003008 if (fence_state) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003009 if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003010 // Export with reference transference becomes external
3011 fence_state->scope = kSyncScopeExternalPermanent;
3012 } else if (fence_state->scope == kSyncScopeInternal) {
3013 // Export with copy transference has a side effect of resetting the fence
3014 fence_state->state = FENCE_UNSIGNALED;
3015 }
3016 }
3017}
3018
3019void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3020 VkResult result) {
3021 if (VK_SUCCESS != result) return;
3022 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3023}
3024
3025void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3026 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3027 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003028 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003029}
3030
3031void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003032 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003033 SWAPCHAIN_NODE *old_swapchain_state) {
3034 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003035 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003036 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003037 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003038 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3039 surface_state->AddParent(swapchain.get());
3040 surface_state->swapchain = swapchain.get();
3041 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003042 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003043 } else {
3044 surface_state->swapchain = nullptr;
3045 }
3046 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003047 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003048 if (old_swapchain_state) {
3049 old_swapchain_state->retired = true;
3050 }
3051 return;
3052}
3053
3054void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3055 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3056 VkResult result) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003057 auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003058 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003059 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003060}
3061
3062void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3063 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003064 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003065}
3066
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003067void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3068 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3069 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3070 VkResult result) {
3071 if (VK_SUCCESS != result) return;
3072 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003073 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003074}
3075
locke-lunargd556cc32019-09-17 01:21:23 -06003076void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
3077 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3078 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003079 auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003080 if (semaphore_state) {
Jeremy Gebben57642982021-09-14 14:14:55 -06003081 semaphore_state->signaler.queue = nullptr;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003082 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06003083 }
3084 }
3085
Tony-LunarG6f887e52021-07-27 11:23:14 -06003086 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003087 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3088 // 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
3089 // confused itself just as much.
3090 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3091 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3092 // Mark the image as having been released to the WSI
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003093 auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003094 if (swapchain_data) {
3095 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003096 if (present_id_info) {
3097 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3098 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3099 }
3100 }
locke-lunargd556cc32019-09-17 01:21:23 -06003101 }
3102 }
3103 // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and
3104 // its semaphore waits) /never/ participate in any completion proof.
3105}
3106
3107void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3108 const VkSwapchainCreateInfoKHR *pCreateInfos,
3109 const VkAllocationCallbacks *pAllocator,
3110 VkSwapchainKHR *pSwapchains, VkResult result) {
3111 if (pCreateInfos) {
3112 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003113 auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003114 auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003115 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
3116 old_swapchain_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06003117 }
3118 }
3119}
3120
3121void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3122 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003123 auto fence_state = Get<FENCE_STATE>(fence);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003124 if (fence_state && fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003125 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3126 // import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003127 fence_state->state = FENCE_INFLIGHT;
Jeremy Gebben57642982021-09-14 14:14:55 -06003128 fence_state->signaler.queue = nullptr; // ANI isn't on a queue, so this can't participate in a completion proof.
locke-lunargd556cc32019-09-17 01:21:23 -06003129 }
3130
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003131 auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003132 if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003133 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3134 // temporary import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003135 semaphore_state->signaled = true;
Jeremy Gebben57642982021-09-14 14:14:55 -06003136 semaphore_state->signaler.queue = nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003137 }
3138
3139 // Mark the image as acquired.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003140 auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003141 if (swapchain_data) {
3142 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003143 }
3144}
3145
3146void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3147 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3148 VkResult result) {
3149 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3150 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3151}
3152
3153void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3154 uint32_t *pImageIndex, VkResult result) {
3155 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3156 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3157 pAcquireInfo->fence, pImageIndex);
3158}
3159
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003160std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3161 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3162}
3163
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003164void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3165 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3166 VkResult result) {
3167 if (result != VK_SUCCESS) {
3168 return;
3169 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003170 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003171 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003172 // this can fail if the allocator fails
3173 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3174 if (result != VK_SUCCESS) {
3175 return;
3176 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003177 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003178 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3179 if (result != VK_SUCCESS) {
3180 return;
3181 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003182
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003183 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003184 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003185 }
3186}
3187
3188// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003189static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003190 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003191}
3192
3193void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3194 uint32_t *pQueueFamilyPropertyCount,
3195 VkQueueFamilyProperties *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}
3200
3201void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003202 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003203 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3204 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003205 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003206}
3207
3208void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003209 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003210 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3211 assert(pd_state);
Jeremy Gebben9f537102021-10-05 16:37:12 -06003212 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003213}
3214void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3215 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003216 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003217}
3218
Jeremy Gebben082a9832021-10-28 13:40:11 -06003219void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003220
3221void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3222 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3223 const VkAllocationCallbacks *pAllocator,
3224 VkSurfaceKHR *pSurface, VkResult result) {
3225 if (VK_SUCCESS != result) return;
3226 RecordVulkanSurface(pSurface);
3227}
3228
3229#ifdef VK_USE_PLATFORM_ANDROID_KHR
3230void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3231 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3232 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3233 VkResult result) {
3234 if (VK_SUCCESS != result) return;
3235 RecordVulkanSurface(pSurface);
3236}
3237#endif // VK_USE_PLATFORM_ANDROID_KHR
3238
3239#ifdef VK_USE_PLATFORM_IOS_MVK
3240void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3241 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3242 VkResult result) {
3243 if (VK_SUCCESS != result) return;
3244 RecordVulkanSurface(pSurface);
3245}
3246#endif // VK_USE_PLATFORM_IOS_MVK
3247
3248#ifdef VK_USE_PLATFORM_MACOS_MVK
3249void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3250 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3251 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3252 VkResult result) {
3253 if (VK_SUCCESS != result) return;
3254 RecordVulkanSurface(pSurface);
3255}
3256#endif // VK_USE_PLATFORM_MACOS_MVK
3257
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003258#ifdef VK_USE_PLATFORM_METAL_EXT
3259void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3260 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3261 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3262 VkResult result) {
3263 if (VK_SUCCESS != result) return;
3264 RecordVulkanSurface(pSurface);
3265}
3266#endif // VK_USE_PLATFORM_METAL_EXT
3267
locke-lunargd556cc32019-09-17 01:21:23 -06003268#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3269void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3270 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3271 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3272 VkResult result) {
3273 if (VK_SUCCESS != result) return;
3274 RecordVulkanSurface(pSurface);
3275}
3276#endif // VK_USE_PLATFORM_WAYLAND_KHR
3277
3278#ifdef VK_USE_PLATFORM_WIN32_KHR
3279void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3280 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3281 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3282 VkResult result) {
3283 if (VK_SUCCESS != result) return;
3284 RecordVulkanSurface(pSurface);
3285}
3286#endif // VK_USE_PLATFORM_WIN32_KHR
3287
3288#ifdef VK_USE_PLATFORM_XCB_KHR
3289void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3290 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3291 VkResult result) {
3292 if (VK_SUCCESS != result) return;
3293 RecordVulkanSurface(pSurface);
3294}
3295#endif // VK_USE_PLATFORM_XCB_KHR
3296
3297#ifdef VK_USE_PLATFORM_XLIB_KHR
3298void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3299 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3300 VkResult result) {
3301 if (VK_SUCCESS != result) return;
3302 RecordVulkanSurface(pSurface);
3303}
3304#endif // VK_USE_PLATFORM_XLIB_KHR
3305
Niklas Haas8b84af12020-04-19 22:20:11 +02003306void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3307 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3308 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3309 VkResult result) {
3310 if (VK_SUCCESS != result) return;
3311 RecordVulkanSurface(pSurface);
3312}
3313
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003314void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3315 VkSurfaceKHR surface,
3316 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3317 VkResult result) {
3318 if (VK_SUCCESS != result) return;
3319 auto surface_state = Get<SURFACE_STATE>(surface);
3320 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3321}
3322
3323void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3324 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3325 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3326 if (VK_SUCCESS != result) return;
3327 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3328 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3329}
3330
3331void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3332 VkSurfaceKHR surface,
3333 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3334 VkResult result) {
3335 auto surface_state = Get<SURFACE_STATE>(surface);
3336 VkSurfaceCapabilitiesKHR caps{
3337 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3338 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3339 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3340 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3341 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3342 };
3343 surface_state->SetCapabilities(physicalDevice, caps);
3344}
3345
locke-lunargd556cc32019-09-17 01:21:23 -06003346void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3347 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3348 VkBool32 *pSupported, VkResult result) {
3349 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003350 auto surface_state = Get<SURFACE_STATE>(surface);
3351 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3352}
3353
3354void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3355 VkSurfaceKHR surface,
3356 uint32_t *pPresentModeCount,
3357 VkPresentModeKHR *pPresentModes,
3358 VkResult result) {
3359 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3360
3361 if (pPresentModes) {
3362 auto surface_state = Get<SURFACE_STATE>(surface);
3363 surface_state->SetPresentModes(physicalDevice,
3364 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3365 }
3366}
3367
3368void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3369 uint32_t *pSurfaceFormatCount,
3370 VkSurfaceFormatKHR *pSurfaceFormats,
3371 VkResult result) {
3372 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3373
3374 if (pSurfaceFormats) {
3375 auto surface_state = Get<SURFACE_STATE>(surface);
3376 surface_state->SetFormats(physicalDevice,
3377 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3378 }
3379}
3380
3381void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3382 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3383 uint32_t *pSurfaceFormatCount,
3384 VkSurfaceFormat2KHR *pSurfaceFormats,
3385 VkResult result) {
3386 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3387
3388 if (pSurfaceFormats) {
3389 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3390 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3391 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3392 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3393 }
3394 surface_state->SetFormats(physicalDevice, std::move(fmts));
3395 }
locke-lunargd556cc32019-09-17 01:21:23 -06003396}
3397
locke-lunargd556cc32019-09-17 01:21:23 -06003398void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3399 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003400 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003401 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003402 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3403}
3404
3405void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003406 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003407 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003408 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3409}
3410
3411void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3412 const VkDebugUtilsLabelEXT *pLabelInfo) {
3413 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3414
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003415 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003416 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3417 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003418 cb_state->debug_label = LoggingLabel(pLabelInfo);
3419}
3420
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003421void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3422 uint32_t queueFamilyIndex,
3423 uint32_t *pCounterCount,
3424 VkPerformanceCounterKHR *pCounters) {
3425 if (NULL == pCounters) return;
3426
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003427 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3428 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003429
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003430 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3431 queue_family_counters->counters.resize(*pCounterCount);
3432 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003433
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003434 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003435}
3436
3437void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3438 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3439 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3440 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3441 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3442}
3443
3444void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3445 VkResult result) {
3446 if (result == VK_SUCCESS) performance_lock_acquired = true;
3447}
3448
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003449void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3450 performance_lock_acquired = false;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06003451 for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003452 cmd_buffer.second->performance_lock_released = true;
3453 }
3454}
3455
locke-lunargd556cc32019-09-17 01:21:23 -06003456void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003457 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003458 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003459 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003460}
3461
3462void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003463 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003464 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003465 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003466}
3467
Mike Schuchardt2df08912020-12-15 16:28:09 -08003468void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3469 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003470 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003471}
3472
Mike Schuchardt2df08912020-12-15 16:28:09 -08003473void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3474 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3475 const VkAllocationCallbacks *pAllocator,
3476 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3477 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003478 if (VK_SUCCESS != result) return;
3479 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3480}
3481
3482void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003483 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3484 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003485 if (VK_SUCCESS != result) return;
3486 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3487}
3488
3489void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003490 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003491 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003492 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3493 assert(template_state);
3494 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003495 // TODO: Record template push descriptor updates
3496 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003497 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
locke-lunargd556cc32019-09-17 01:21:23 -06003498 }
3499 }
3500}
3501
3502void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3503 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3504 const void *pData) {
3505 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3506}
3507
3508void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003509 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003510 const void *pData) {
3511 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3512}
3513
Mike Schuchardt2df08912020-12-15 16:28:09 -08003514void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3515 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3516 VkPipelineLayout layout, uint32_t set,
3517 const void *pData) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003518 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003519
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003520 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003521 const auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003522 if (template_state) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003523 auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003524 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003525 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003526 // Decode the template into a set of write updates
Jeremy Gebben9f537102021-10-05 16:37:12 -06003527 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003528 dsl->GetDescriptorSetLayout());
Jeremy Gebben9f537102021-10-05 16:37:12 -06003529 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data.get(), set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003530 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3531 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003532 }
3533}
3534
3535void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3536 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003537 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003538 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003539 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003540 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003541 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003542 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003543 }
3544}
3545
3546void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3547 uint32_t *pPropertyCount,
3548 VkDisplayPlanePropertiesKHR *pProperties,
3549 VkResult result) {
3550 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3551 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3552}
3553
3554void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3555 uint32_t *pPropertyCount,
3556 VkDisplayPlaneProperties2KHR *pProperties,
3557 VkResult result) {
3558 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3559 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3560}
3561
3562void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3563 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3564 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003565 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003566 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003567 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003568}
3569
3570void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3571 uint32_t query, uint32_t index) {
3572 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003573 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003574 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003575 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003576}
3577
3578void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3579 VkSamplerYcbcrConversion ycbcr_conversion) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003580 VkFormatFeatureFlags format_features = 0;
3581
3582 if (create_info->format != VK_FORMAT_UNDEFINED) {
3583 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003584 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003585 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3586 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003587 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003588
Jeremy Gebben082a9832021-10-28 13:40:11 -06003589 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003590}
3591
3592void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3593 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3594 const VkAllocationCallbacks *pAllocator,
3595 VkSamplerYcbcrConversion *pYcbcrConversion,
3596 VkResult result) {
3597 if (VK_SUCCESS != result) return;
3598 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3599}
3600
3601void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3602 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3603 const VkAllocationCallbacks *pAllocator,
3604 VkSamplerYcbcrConversion *pYcbcrConversion,
3605 VkResult result) {
3606 if (VK_SUCCESS != result) return;
3607 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3608}
3609
3610void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3611 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003612 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003613}
3614
3615void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3616 VkSamplerYcbcrConversion ycbcrConversion,
3617 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003618 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003619}
3620
Tony-LunarG977448c2019-12-02 14:52:02 -07003621void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3622 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003623 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003624 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003625
3626 // Do nothing if the query pool has been destroyed.
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003627 auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003628 if (!query_pool_state) return;
3629
3630 // Reset the state of existing entries.
locke-lunargd556cc32019-09-17 01:21:23 -06003631 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3632 for (uint32_t i = 0; i < max_query_count; ++i) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003633 auto query_index = firstQuery + i;
3634 query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003635 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003636 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07003637 query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003638 }
3639 }
locke-lunargd556cc32019-09-17 01:21:23 -06003640 }
3641}
3642
Tony-LunarG977448c2019-12-02 14:52:02 -07003643void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3644 uint32_t queryCount) {
3645 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3646}
3647
3648void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3649 uint32_t queryCount) {
3650 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3651}
3652
locke-lunargd556cc32019-09-17 01:21:23 -06003653void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003654 const UPDATE_TEMPLATE_STATE *template_state,
3655 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003656 // Translate the templated update into a normal update for validation...
3657 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3658 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3659 decoded_update.desc_writes.data(), 0, NULL);
3660}
3661
3662// Update the common AllocateDescriptorSetsData
3663void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003664 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003665 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06003666 auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003667 if (layout) {
3668 ds_data->layout_nodes[i] = layout;
3669 // Count total descriptors required per type
3670 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3671 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003672 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3673 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003674 }
3675 }
3676 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3677 }
3678}
3679
locke-lunargd556cc32019-09-17 01:21:23 -06003680void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3681 uint32_t firstVertex, 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_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003684}
3685
Tony-LunarG745150c2021-07-02 15:07:31 -06003686void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3687 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3688 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003689 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003690 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003691}
3692
locke-lunargd556cc32019-09-17 01:21:23 -06003693void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
3694 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
3695 uint32_t firstInstance) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003696 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003697 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003698}
3699
Tony-LunarG745150c2021-07-02 15:07:31 -06003700void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3701 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
3702 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
3703 const int32_t *pVertexOffset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003704 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003705 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003706}
3707
locke-lunargd556cc32019-09-17 01:21:23 -06003708void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3709 uint32_t count, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003710 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3711 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003712 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003713 if (!disabled[command_buffer_state]) {
3714 cb_state->AddChild(buffer_state);
3715 }
locke-lunargd556cc32019-09-17 01:21:23 -06003716}
3717
3718void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3719 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003720 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3721 auto buffer_state = Get<BUFFER_STATE>(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003722 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003723 if (!disabled[command_buffer_state]) {
3724 cb_state->AddChild(buffer_state);
3725 }
locke-lunargd556cc32019-09-17 01:21:23 -06003726}
3727
3728void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003729 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003730 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06003731}
3732
3733void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3734 VkDeviceSize offset) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003735 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003736 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003737 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003738 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003739 cb_state->AddChild(buffer_state);
3740 }
locke-lunargd556cc32019-09-17 01:21:23 -06003741}
3742
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003743void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3744 uint32_t, uint32_t) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003745 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003746 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3747}
3748
3749void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3750 uint32_t, uint32_t) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003751 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003752 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3753}
3754
Tony-LunarG977448c2019-12-02 14:52:02 -07003755void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3756 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07003757 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003758 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003759 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003760 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003761 auto buffer_state = Get<BUFFER_STATE>(buffer);
3762 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003763 cb_state->AddChild(buffer_state);
3764 cb_state->AddChild(count_buffer_state);
3765 }
Tony-LunarG977448c2019-12-02 14:52:02 -07003766}
3767
locke-lunargd556cc32019-09-17 01:21:23 -06003768void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3769 VkDeviceSize offset, VkBuffer countBuffer,
3770 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3771 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003772 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003773 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003774}
3775
3776void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3777 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
3778 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003779 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003780 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07003781}
3782
3783void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3784 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07003785 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003786 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003787 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003788 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003789 auto buffer_state = Get<BUFFER_STATE>(buffer);
3790 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003791 cb_state->AddChild(buffer_state);
3792 cb_state->AddChild(count_buffer_state);
3793 }
locke-lunargd556cc32019-09-17 01:21:23 -06003794}
3795
3796void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3797 VkDeviceSize offset, VkBuffer countBuffer,
3798 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3799 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003800 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003801 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003802}
3803
3804void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
3805 VkDeviceSize offset, VkBuffer countBuffer,
3806 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3807 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003808 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003809 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06003810}
3811
3812void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
3813 uint32_t firstTask) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003814 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003815 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003816}
3817
3818void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
3819 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003820 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003821 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003822 auto buffer_state = Get<BUFFER_STATE>(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003823 if (!disabled[command_buffer_state] && buffer_state) {
3824 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003825 }
3826}
3827
3828void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
3829 VkDeviceSize offset, VkBuffer countBuffer,
3830 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3831 uint32_t stride) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003832 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003833 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003834 if (!disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003835 auto buffer_state = Get<BUFFER_STATE>(buffer);
3836 auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003837 if (buffer_state) {
3838 cb_state->AddChild(buffer_state);
3839 }
3840 if (count_buffer_state) {
3841 cb_state->AddChild(count_buffer_state);
3842 }
locke-lunargd556cc32019-09-17 01:21:23 -06003843 }
3844}
3845
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003846void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
3847 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
3848 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
3849 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
3850 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
3851 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
3852 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003853 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003854 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003855 cb_state->hasTraceRaysCmd = true;
3856}
3857
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003858void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
3859 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
3860 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
3861 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
3862 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
3863 uint32_t height, uint32_t depth) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003864 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003865 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003866 cb_state->hasTraceRaysCmd = true;
3867}
3868
3869void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
3870 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
3871 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
3872 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
3873 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
3874 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003875 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003876 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003877 cb_state->hasTraceRaysCmd = true;
3878}
3879
locke-lunargd556cc32019-09-17 01:21:23 -06003880void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
3881 const VkAllocationCallbacks *pAllocator,
3882 VkShaderModule *pShaderModule, VkResult result,
3883 void *csm_state_data) {
3884 if (VK_SUCCESS != result) return;
3885 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
3886
sfricke-samsung45996a42021-09-16 13:45:27 -07003887 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06003888 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003889 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
3890 csm_state->unique_shader_id)
3891 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06003892 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06003893}
3894
John Zulauf22b0fbe2019-10-15 06:26:16 -06003895void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
3896 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
3897 VkResult result) {
3898 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben9f537102021-10-05 16:37:12 -06003899 auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06003900
3901 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
3902
3903 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06003904 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07003905 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07003906 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06003907
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003908 auto format_features =
3909 GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format,
3910 swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06003911
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06003912 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003913 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003914 if (!swapchain_image.fake_base_address) {
3915 auto size = image_state->fragment_encoder->TotalSize();
3916 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07003917 }
3918
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003919 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003920 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06003921 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06003922 }
3923 }
3924
3925 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06003926 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
3927 }
3928}
sourav parmar35e7a002020-06-09 17:58:44 -07003929
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02003930void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
3931 const VkCopyAccelerationStructureInfoKHR *pInfo,
3932 VkResult result) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003933 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
3934 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02003935 if (dst_as_state != nullptr && src_as_state != nullptr) {
3936 dst_as_state->built = true;
3937 dst_as_state->build_info_khr = src_as_state->build_info_khr;
3938 }
3939}
3940
sourav parmar35e7a002020-06-09 17:58:44 -07003941void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
3942 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003943 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07003944 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003945 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003946 auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
3947 auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07003948 if (dst_as_state != nullptr && src_as_state != nullptr) {
3949 dst_as_state->built = true;
3950 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003951 if (!disabled[command_buffer_state]) {
3952 cb_state->AddChild(dst_as_state);
3953 cb_state->AddChild(src_as_state);
3954 }
sourav parmar35e7a002020-06-09 17:58:44 -07003955 }
3956 }
3957}
Piers Daniell39842ee2020-07-10 16:42:33 -06003958
3959void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003960 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003961 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003962}
3963
3964void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003965 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003966 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003967}
3968
3969void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
3970 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003971 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003972 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003973 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06003974}
3975
3976void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
3977 const VkViewport *pViewports) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003978 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003979 cb_state->RecordStateCmd(CMD_SETVIEWPORTWITHCOUNTEXT, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07003980 uint32_t bits = (1u << viewportCount) - 1u;
3981 cb_state->viewportWithCountMask |= bits;
3982 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00003983 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07003984 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07003985
3986 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
3987 for (size_t i = 0; i < viewportCount; ++i) {
3988 cb_state->dynamicViewports[i] = pViewports[i];
3989 }
Piers Daniell39842ee2020-07-10 16:42:33 -06003990}
3991
3992void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
3993 const VkRect2D *pScissors) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06003994 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003995 cb_state->RecordStateCmd(CMD_SETSCISSORWITHCOUNTEXT, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07003996 uint32_t bits = (1u << scissorCount) - 1u;
3997 cb_state->scissorWithCountMask |= bits;
3998 cb_state->trashedScissorMask &= ~bits;
3999 cb_state->scissorWithCountCount = scissorCount;
4000 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004001}
4002
4003void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4004 uint32_t bindingCount, const VkBuffer *pBuffers,
4005 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4006 const VkDeviceSize *pStrides) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004007 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004008 cb_state->RecordStateCmd(CMD_BINDVERTEXBUFFERS2EXT, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004009
4010 uint32_t end = firstBinding + bindingCount;
4011 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4012 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4013 }
4014
4015 for (uint32_t i = 0; i < bindingCount; ++i) {
4016 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
Jeremy Gebben9f537102021-10-05 16:37:12 -06004017 vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004018 vertex_buffer_binding.offset = pOffsets[i];
4019 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4020 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4021 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004022 if (!disabled[command_buffer_state] && pBuffers[i]) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06004023 cb_state->AddChild(vertex_buffer_binding.buffer_state);
Piers Daniell39842ee2020-07-10 16:42:33 -06004024 }
4025 }
4026}
4027
4028void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004029 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004030 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004031}
4032
4033void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004034 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004035 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004036}
4037
4038void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004039 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004040 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004041}
4042
4043void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4044 VkBool32 depthBoundsTestEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004045 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004046 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004047}
4048void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
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_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004051}
4052
4053void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4054 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4055 VkCompareOp compareOp) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004056 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004057 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004058}
locke-lunarg4189aa22020-10-21 00:23:48 -06004059
4060void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4061 uint32_t discardRectangleCount,
4062 const VkRect2D *pDiscardRectangles) {
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_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004065}
4066
4067void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4068 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004069 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004070 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004071}
4072
4073void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4074 VkCoarseSampleOrderTypeNV sampleOrderType,
4075 uint32_t customSampleOrderCount,
4076 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004077 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004078 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004079}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004080
4081void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004082 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004083 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004084}
4085
4086void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004087 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004088 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004089}
4090
4091void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4092 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004093 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004094 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004095}
4096
4097void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004098 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004099 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004100}
4101
4102void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4103 VkBool32 primitiveRestartEnable) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004104 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004105 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004106}
Piers Daniell924cd832021-05-18 13:48:47 -06004107
4108void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4109 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4110 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4111 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004112 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004113 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4114
4115 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4116 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4117 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004118 if (pipeline_state->create_info.graphics.pDynamicState) {
4119 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4120 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004121 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4122 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4123 break;
4124 }
4125 }
4126 }
4127 }
4128 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004129}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004130
4131void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06004132 auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004133 if (buffer_state) {
4134 // address is used for GPU-AV and ray tracing buffer validation
4135 buffer_state->deviceAddress = address;
Jeremy Gebben65975ed2021-10-29 11:16:10 -06004136 buffer_address_map_.insert(address, buffer_state.get());
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004137 }
4138}
4139
4140void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4141 VkDeviceAddress address) {
4142 RecordGetBufferDeviceAddress(pInfo, address);
4143}
4144
4145void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4146 VkDeviceAddress address) {
4147 RecordGetBufferDeviceAddress(pInfo, address);
4148}
4149
4150void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4151 VkDeviceAddress address) {
4152 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004153}
4154
4155std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4156 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004157 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004158}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004159
4160std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4161 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004162 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004163 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4164}